Hi,
I have a function that lists all posts in a category and also, all the sub-posts in that category:
function list_advertisers_business() {
$cats = get_categories('include=7');
echo '<ul class="cat-list">';
foreach($cats as $cat) :
//only loop through categories which have subcategories
if( get_categories('parent='.$cat->term_id) ) :
$cat_name=$cat->slug;
echo '<ul>';
// get the direct sub categories
$sub_cats = get_categories('parent='.$cat->term_id);
foreach($sub_cats as $sub_cat) :
$sub_cat_name=$sub_cat->slug;
echo ' <div id="category-header">' . $sub_cat->name; ?></div><?
// get all posts with that category
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$cat_posts = get_posts('numberposts=3&paged=$paged&category_name='.$sub_cat_name);
foreach($cat_posts as $post) :
setup_postdata($post);
?>
<div id="query">
<div class="advertiser-table">
<h2 class="advertiser-name"><? $Company = get_post_meta($post->ID, 'Company', true); if($Company != ''){ echo $Company; } ?></h2>
<span class="advertiser-details">
<? require 'data-table.inc'; ?>
</span>
</div>
</div>
<?
endforeach; // closes 'foreach($cat_posts as $post)'
endforeach; // closes 'foreach($sub_cats as $sub_cat)'
echo '</ul></li>';
endif;
endforeach; // closes 'foreach($cats as $cat)'
echo '</ul>';
}
I added a pagination code block in there:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$cat_posts = get_posts('numberposts=3&paged=$paged&category_name='.$sub_cat_name);
but it doesn't seem to work. I have WP-Pagination installed and I used the call to that function and it doesn't work either. It's like my code is immune to pagination. When I say it doesn't work, i mean that i get no pagination but no real decriptive errors or any error at all either.
Can anyone who can read this php better than me help please. I wrote it a while ago and can't really remember how it works or what I am doing wrong.
Thank you very much for your time.
James