Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Center area post/pages (http://forum.bytesforall.com/forumdisplay.php?f=32)
-   -   [SOLVED] Mixing static content + excerpts on home and category pages ? (http://forum.bytesforall.com/showthread.php?t=14145)

jmc34 May 13, 2011 06:12 AM

[SOLVED] Mixing static content + excerpts on home and category pages ?
 
Hi there,
I am working on the web site of my bike club and would like to be able to mix static HTML content and excerpts on both the home page and *some* category pages.

I am new to all this WP thing, and I must say that I do not know where to start.

I was thinking that I would put my static HTML content into files that I can then include, but that is the only hint I do have.

Here might not be the right place to ask this question (as I am not sure if it is a theme question or a WP question), so feel free to point me in the right direction.

Any pointers will be much appreciated.

Subsequently I might want to display exerpts on the home in two columns (I saw a sticky about that) en have different number of excerpts for some categories, but we will cross that bridge when we will cross that bridge.

Thanks in advance for your help.

Jean-Michel.

lmilesw May 13, 2011 09:48 AM

There is a custom query page template in the Gold forum that may do what you want. I typically use the List Category Posts plugin for that type of functionality.

jmc34 May 13, 2011 10:00 AM

Hi Miles,
not sure what the gold forum is (did not find it) but at the fisrt glance it would seem that this plugin will do the trick.

Hopefully it is not too heavy as my ISP only allows 32M for PHP, that does not allow for much plugin fantasy at all (especially on a 64bits server)...

I'll give it a go.

Thanks again,
JM

jmc34 May 13, 2011 10:43 AM

Hmmm...

This plugin is a start, but not really what I was looking for...

Have a look : http://jeanmichel.cazaux.free.fr/sit...ex.php/courses

I am trying to have the static content displayed in its own "box" and then the posts formated as "normal" excerpts...

Almost like if the static content was the first post of the page displayed "in full" and then the exerpts (somle of them)...

Any other hint?
I am happy (and probably can) do a bit of basic PHP tweaking if I have to.

Thanks
JM

lmilesw May 13, 2011 10:55 AM

What did you use for the plugins shortcode. You should be able to use something like the following to give you a list if excerpts from 10 posts in a category or categories In this case categories 12 and 13.
There is a list of all the attributes for this plugin on the Other Notes tab.

[catlist id=12,13 excerpt=yes numberposts=10]

jmc34 May 13, 2011 11:36 PM

I did use those keywords (exactly [catlist name=courses excerpt=yes comment=yes thumbnail=yes]), and it does show the right things, but not really in the format I am expecting...

I think I might throw myself in modifying the index.php just a bit...

Sounds like a good challenge but makes each upgrade then more difficult (this stated I am stuck with 3.5.3 due to the Suhosin issue...

I you have other ideas, please fire!

Thanks, JM

lmilesw May 14, 2011 08:06 AM

How do you want them to show?

jmc34 May 15, 2011 01:44 AM

I'd like my page to show excerpts formatted "by default" plus some static content (possibly coming from a file, but that is an option).

The static content would only show on excerpts pages, post pages would show "as normal" posts.

A bit like this:
http://jeanmichel.cazaux.free.fr/sit...c+excerpts.png

What i was thinking (to make it a bit generic) is to have my static content in a file named according to a defined schema (for example static_insert_cat_[ID].html, where [ID] would be the category ID) and in index.html I can test if this file exists and include it if it does.

This assumes that:
- I can and know how to test what category I am displaying;
- I can and know how to test if I am on an excerpts page or a normal page...

But I would be surprised if I cannot do that.

Thanks,
JM

aQuickStudy May 15, 2011 10:13 PM

Couldn't you add a widget area to the top of the center column and use a widget for your static content?

jmc34 May 16, 2011 01:51 AM

I did not know you could put a widget on the center column...

Is this possible?

JM

jmc34 May 16, 2011 02:14 AM

Ok, after a bit of tinkering with index.php, I eventually got where I wanted to be...

In the current guise, my solution includes the content of a file named static_heading_cat_slug.html or static_heading_cat_id.html before the posts of category slug (or with ID id) on an excerpts page.

The content of the file will be displayed above the posts and after the navigation section.

If some static content is found, the number of excerpts is limited to 3 (I did not find a way to make this variable).

I could have stopped there but decided to add a bit of icing on the cake...

If there are no posts to display, I try to include a file named:
-static_empty_cat_slug.html
-static_empty_cat_id.html
-static_heading_cat_slug.html
-static_heading_cat_id.html

The first file matching one of these names is included. This allows for having a longuer/different static content when there are no posts.

As well, the 'no_content_found' content is not displayed if some static content is found.

That is a bit complex maybe, but while at it, I thought I would cover the last mile.

I modified the wordpress/theme/atahualpaXXX/index.php file as follows:

Between
Code:

        <?php /* This outputs the next/previous post or page navigation.
        This can be edited at Atahualpa Theme Options -> Style & edit the Center column */
        bfa_center_content($bfa_ata['content_above_loop']); ?>

and
Code:

        <?php /* The LOOP starts here. Do this for all posts: */
        while (have_posts()) : the_post(); $bfa_ata['postcount']++; ?>

(around line 13), add the following :
Code:

        <?php /* STATIC_CONTENT_ON_CATEGORIES */
        $included_static_content = false;
        if (is_category() && !is_single()) {
                // we are on a category page and not on a single post page
                // We get the category (not as simple as get_the_category() that gives erroneaou results
                global $wp_query;
                $cat_ID = get_query_var('cat');
                $category = get_category($cat_ID,false);
                /* Do we have a static content file for this category ?
                We build an array with possible filenames (in order of precedence)... */                               
                $upload_dir = wp_upload_dir();
                $filenames = array();
                $filenames[0] = $upload_dir[basedir]."/static_heading_cat_".$category->slug.".html";
                $filenames[1] = $upload_dir[basedir]."/static_heading_cat_".$category->term_id.".html";
               
                /* We try each file(name) in the array */
                foreach ($filenames as $i => $filename) {
                        if (file_exists($filename)) {
                                include($filename);
                                $included_static_content = true;
                                break;
                        }
                }               
        }
        ?>

This will include the static files above the posts when there are posts.

After
Code:

                <?php /* This is the actual Wordpress LOOP.
                The output can be edited at Atahualpa Theme Options -> Style & edit the Center column */
                bfa_center_content($bfa_ata['content_inside_loop']); ?>

add:
Code:

                <?php
                /* STATIC_CONTENT_ON_CATEGORIES */
                if ($included_static_content && $bfa_ata['postcount']==3) {
                        // We need to limit the number of excerpts
                        break;
                }
                ?>

This will stop the loop after the 3rd post if we have included static content.

Then we will take care of the case when there were no posts...

Towards the end of the file REPLACE :
Code:

<?php /* END of: If there are any posts */
else : /* If there are no posts: */ ?>

<?php /* This outputs the "Not Found" content, if neither posts, pages nor attachments are available for the requested page.
This can be edited at Atahualpa Theme Options -> Style & edit the Center column */
bfa_center_content($bfa_ata['content_not_found']); ?>

with:

Code:

<?php /* END of: If there are any posts */
else : /* If there are no posts: */
        /* STATIC_CONTENT_ON_CATEGORIES */
        $included_static_content = false;
        if (is_category()) {
                // we are on a category page and not on a single post page
                // We get the category (not as simple as get_the_category() that gives erroneaou results
                global $wp_query;
                $cat_ID = get_query_var('cat');
                $category = get_category($cat_ID,false);
                /* Do we have a static content file for this category ?
                We build an array with possible filenames (in order of precedence)... */                               
                $upload_dir = wp_upload_dir();
                $filenames = array();
               
                $filenames[0] = $upload_dir[basedir]."/static_empty_cat_".$category->slug.".html";
                $filenames[1] = $upload_dir[basedir]."/static_empty_cat_".$category->term_id.".html";
                $filenames[2] = $upload_dir[basedir]."/static_heading_cat_".$category->slug.".html";
                $filenames[3] = $upload_dir[basedir]."/static_heading_cat_".$category->term_id.".html";
               
                /* We try each file(name) in the array */
                foreach ($filenames as $i => $filename) {
                        if (file_exists($filename)) {
                                include($filename);
                                $included_static_content = true;
                                break;
                        }
                }               
        }

        /* This outputs the "Not Found" content, if neither posts, pages nor attachments are available for the requested page.
        This can be edited at Atahualpa Theme Options -> Style & edit the Center column */
        /* STATIC_CONTENT_ON_CATEGORIES
                We only included 'content_not_found' if no static content has been found */
        if (!$included_static_content)
                bfa_center_content($bfa_ata['content_not_found']); ?>

This will look for the various files we can include there and will NOT display $bfa_ata['content_not_found'] is one of the files was found.

Ah, last detail, this assumes the files are in the wordpress/uploads directory.

I hope this will be useful to someone, please feel free to use and reuse.

Jean-Michel

jmc34 May 16, 2011 02:18 AM

And you can even find the edited index.php (as index_php.txt) here.

Enjoy,
Jean-Michel


All times are GMT -6. The time now is 08:02 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.