【问题标题】:Pagination for custom post type in Wordpress not working?Wordpress 中自定义帖子类型的分页不起作用?
【发布时间】:2012-10-26 09:11:48
【问题描述】:

自定义类型帖子中的分页代码

<?php  $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; // For pagination

$loop = new WP_Query( array('post_type' => 'Portfolio','posts_per_page' => 3,'orderby'=> 'menu_order',
'paged'=>$paged ) ); ?> //For implementing pagination
<?php if ($loop->have_posts()): ?>
<?php while ($loop->have_posts()) : $loop->the_post(); ?> <div id="latestproimg">
<a href="<?php the_permalink(); ?>" rel="bookmark">
<?php the_post_thumbnail('large', array('title' => false)); ?></a>
</div>
<div id="latestpostser">
<h2 class="entry-title"><a href="<?php the_permalink(); ?>" rel="bookmark">
<?php echo get_the_title(); ?></a></h2> //displaying the title
<?php //echo get_the_excerpt(); ?>
<?php //the_content( 'Read the full post »' ); ?> // for displaying the content
</div>
<div class="clr"></div>
<?php endwhile;
endif; ?>

请告诉我代码中的错误在哪里

【问题讨论】:

    标签: wordpress post pagination


    【解决方案1】:

    即使我已经放置了 $page 选项,我也遇到了这个奇怪的分页问题,​​但是解决我的问题的方法是尝试将 paged 参数更改为 get_query_var 的 page功能

    $paged = ( get_query_var('page') ) ? get_query_var('page') : 1; // For pagination
    

    让我知道它是否有效

    【讨论】:

    • 几个月前这对我有用,而且由于某些奇怪的原因,我不得不将存储查询的对象重命名为“$the_query”。
    【解决方案2】:

    如果永久链接设置将 url 更改为 http://domain.com/page/2/... 之类的内容,get_query_var('paged') 将不起作用。因此,@IoQ 的答案更灵活的版本是,

    $search_values['paged'] = (get_query_var('paged')) ? get_query_var('paged')
    : ((get_query_var('page')) ? get_query_var('page') : 1);
    

    如果永久链接设置为类似 postname 或 paged=xx 是 url 的一部分,则此方法有效

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-15
      • 2011-03-20
      • 2014-05-21
      相关资源
      最近更新 更多