Forums

[resolved] Query posts and pagenavi (5 posts)

  1. stevenoi
    Member
    Posted 2 years ago #

    Hi, I made a blog template for my blog page and it must show every category except the "uncategorized" category. I've made a code that worked, but now when I install pagenavi I can't go to another page ( the same I had for the next and previous post link ). This is my code : `
    <?php
    /*
    Template name: blog
    */
    ?>

    <?php get_header(); ?>

    <div id="content">
    <div class="head"><h1>Blog</h1></div>
    <div id="block-3">

    <div id="content2">

    <?php query_posts("cat=-1"); ?>
    <?php while (have_posts()) : the_post(); ?>

    <div class="post">

    <div id="post_top">
    <div class="title"> "><?php the_title(); ?></div>
    <div class="comments"><?php comments_popup_link('0 Comments', '1 Comment', '% Comments'); ?></div>
    </div>

    <div class="pcontent">

    <?php the_content(); ?>
    </div>

    <div class="info_right">
    Author : <?php the_author_posts_link(); ?>
    Category : <?php the_category(' '); ?>
    Date : <?php the_time('d-m-y'); ?>
    Tags : <?php the_tags(' '); ?>
    </div>

    </div>
    <?php endwhile; ?>

    <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>

    </div>
    <div id="sidebar">
    <?php get_search_form(); ?>
    <div class="sidebaritem">
    <h2>Categories</h2>

      <?php
      wp_list_categories('orderby=id&show_count=1&exclude=1&title_li='); ?>

    </div>
    <?php get_sidebar(); ?>

    </div>

    </div>
    </div>
    <?php get_footer(); ?>

    <?php endwhile; ?>
    </div>
    <!-- End Row 3 --!>
    </div>

    </div>

    <!-- End Block 2 --!>

    <?php endif; ?>
    <?php get_footer(); ?>
    `

    And it will show up like this : http://hee.awardspace.biz/blog/ . As you see it shows the same posts if you go to another page. I already figured out that the query_posts where the problem, but I don't know another way...

    - Steven

  2. stevenoi
    Member
    Posted 2 years ago #

    Bump ... ?

  3. stvwlf
    Member
    Posted 2 years ago #

    hi

    to have paging work correctly when using query_posts, you must use code like this

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
          query_posts("cat=-1&amp;paged=$paged"); ?>

    Try that - it should resolve the problem. Haven't tried this with the PageNavi plugin yet.

  4. stevenoi
    Member
    Posted 2 years ago #

    Thank you very much, it worked! Thank you again!!!!

  5. michael yoeh
    Member
    Posted 1 year ago #

    but why I add what you said to my code,it didn't work.

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('cat=22&offset=1&paged=$paged&posts_per_page=10');?>
    <?php while(have_posts()):the_post();?>
    <div class="listitem">
    <h1><?php the_title();?></h1>
    <?php if(get_post_meta($post->ID,'topic_image','true')):?>
    <?php $image=get_post_meta($post->ID,'topic_image','true');?>
    <img src="<?php echo $image;?>" />
    <?php else:?>
    <img src="<?php bloginfo('template_url')?>/custom_images/default.jpg" />
    <?php endif;?>
    <?php the_excerpt();?><a href="<?php the_permalink();?>">[MORE]</a>
    </div>
    <?php endwhile;?>
    <?php if(function_exists('wp_page_numbers')) : wp_page_numbers(); endif; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic