Wordpress posts_per_page Query Option Not Working
Fixing the posts_per_page query parameter bug in Carrington Themes
query_posts('cat=234&posts_per_page=5); remove_filter('pre_get_posts', 'cfct_posts_per_archive_page');
<?php
/*
Template Name: SomethingTemplate
*/
if (__FILE__ == $_SERVER['SCRIPT_FILENAME']) { die(); }
if (CFCT_DEBUG) { cfct_banner(__FILE__); }
get_header();
?>
<div id="content">
<?php
// get category id by name - if you know it then skip this and add it directly to the query
$id = get_cat_id('Some Category');
// remove the carrington blog filter that overwrites the posts_per_page query filter parameter
remove_filter('pre_get_posts', 'cfct_posts_per_archive_page');
// create a query to filter by the desired category and show the number of posts as specified in the global settings and handle paging
query_posts('cat='.$id.'&posts_per_page='.get_option('posts_per_page') . '&paged='.$paged);
if (have_posts()) {
while (have_posts()) {
the_post();?>
<h1><a href="<?php the_permalink(); ?>" title="This is my blog article: <?php htmlspecialchars(the_title()) ?>"><?php the_title(); ?></a></h1>
<?php the_content(); ?>
<?php
}
}
?>
<div class="pagination">
<span class="previous"><?php previous_posts_link('« Previous') ?></span>
<span class="next"><?php next_posts_link('Next »') ?></span>
</div>
</div>
Labels: Bugs, Carrington, PHP, posts_per_page, the_loop, Theme, Wordpress



2 Comments:
thanks, it saved my weekend
thanks! it saved my weekend
Post a Comment
Subscribe to Post Comments [Atom]
Links to this post:
Create a Link
<< Home