WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Excluding category 1 on Home page breaks pagination (4 posts)

  1. Jake Osborne
    Member
    Posted 3 years ago #

    In my theme I wish to exclude all posts in category 1 from showing on the home page; so I have added the first three lines of the code below to my loop.php template file. This works in showing only the other categories; however it breaks my pagination; when the "next" button is pressed it simply returns the same posts as before.

    <?php if ( is_home() ) {
    query_posts($query_string . '&cat=-1');
    } ?>
    
    <?php if ( have_posts() ) : ?>
        <?php while ( have_posts() ) : the_post(); ?>
    ...

    Any insight would be most appreciated.

  2. Reuben Gunday
    Member
    Posted 3 years ago #

    <?php if ( is_home() ) {
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts($query_string . '&cat=-1&paged='.$paged);
    } ?>
  3. Jake Osborne
    Member
    Posted 3 years ago #

    Thanks!

  4. kirthgersen25
    Member
    Posted 2 years ago #

    Hi, i have a problem similar to Jake. The code above worked fine for me, i have excluded all posts of category 2 from my homepage and the pagination works, but is always showing an extra blank page at the end of pagination. Instead of 2 pages with posts, it's showing 2 pages with posts and 1 extra page blank.

    I have workpress 3.1.3 and the theme "journal crunch" that use the function "emm_paginate" for the pagination. See http://www.ericmmartin.com/pagination-function-for-wordpress/.

    I inserted the code above in the home.php, before the
    'if (have_posts()) : while (have_posts()) : the_post(); ?>', and commented out the code of the theme for posting the posts with the tag "homepost" to the homepage because it was in conflict with the code.

    See the code of home.php:
    '.........
    .........
    <?php $postindex = 1; /* begin comment out
    if(!query_posts('showposts='.get_option('journal_home_posts').'&tag=homepost')){
    if(get_option('journal_home_posts')!=''){
    query_posts('showposts='.get_option('journal_home_posts'));
    }else{
    query_posts('showposts=6');
    }
    }else{
    query_posts('showposts='.get_option('journal_home_posts').'&tag=homepost');
    if(get_option('journal_home_posts')!=''){
    query_posts('showposts='.get_option('journal_home_posts').'&tag=homepost');
    }else{
    query_posts('showposts=6&tag=homepost');
    }
    } ends comment out */

    if ( is_home() ) {
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts($query_string . '&cat=-2&paged='.$paged);
    }

    if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div class="postBox <?php if(($postindex % 3) == 0){ echo 'lastBox';}?>">
    <div class="postBoxInner">

    <?php
    if(has_post_thumbnail()) {
    //the_post_thumbnail();?>
    <img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php echo get_image_path($post->ID); ?>&h=90&w=255&zc=1" alt="<?php the_title(); ?>"> '

    and in the ends of the page, i inserted after '<?php endif;
    wp_reset_query();?>' the code

    '<div style="clear:both;"></div>
    <?php if (function_exists("emm_paginate")) {
    emm_paginate();
    } ?>
    </div>' that enables the pagination on my homepage.

Topic Closed

This topic has been closed to new replies.

About this Topic