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