【问题标题】:Wordpress 3.5 pagination for postsWordpress 3.5 的帖子分页
【发布时间】:2013-01-23 23:42:54
【问题描述】:

我无法在显示特定类别帖子的页面中进行分页工作。 分页显示,但它不会改变页面。一些帮助会很棒,谢谢!

这是我在 index.php 文件中的代码:

<?php
if (is_page('Blog') || is_category('Blogposts')) { 
$post_per_page = '3'; 
$args=array('category_name' => 'Blogposts', 'posts_per_page' => $post_per_page);
?>

<?php 
query_posts($args); 
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <div class="post" id="post-<?php the_ID(); ?>">
        <h1><a href="<?php the_permalink(); ?>" title="<?php the_title();?>"><?php          the_title(); ?></a></h1>
            <p><?php the_time('j.n.Y')?></<p>
            <p><?php comments_number('No comments','1 comment','% comments'); ?></p>
        <?php the_content(); ?>
    </div>

  <?php endwhile; 
      endif; 

  wp_pagenavi();

 next_posts_link('« Previous Post' );
 previous_posts_link('Next Post »' );

 }

 ?>

【问题讨论】:

    标签: wordpress pagination


    【解决方案1】:
    <?php
         $category=get_category_by_slug('home');
    
       $category_id = $category->term_id;
    
       $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
             query_posts( "cat=5&showposts=2&paged=".$paged);
       if (have_posts()) : while (have_posts()) : the_post();
    
       ?>
    
     <div class="contentTitle"> <?php the_title(); ?> </div>
     <div class="contentText"><?php the_content();?> </div>
    
       <?php  endwhile; endif; ?>
       <?php if(function_exists('wp_pagenavi')) : ?>
                               <div class=`enter code here`"pnavi">
                <?php wp_pagenavi(); ?>
                               </div>
            <?php else : ?>
                <div class="alignleft"><?php// next_posts_link(__('&laquo; Older Entries')); ?></div>
                <div class="alignright"><?php// previous_posts_link(__('Newer Entries &raquo;')); ?></div>
            <?php endif; ?>
    

    【讨论】:

    • 请解释您的代码。 (“为什么它解决了这个问题?”)
    【解决方案2】:

    使用类似的东西

    $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args=array('category_name' => 'Blogposts', 'posts_per_page' => $post_per_page, 'paged' => $page);
    

    在您的第一个代码中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多