【问题标题】:Paginating wordpress custom queries分页 wordpress 自定义查询
【发布时间】:2010-09-26 09:56:57
【问题描述】:

我如何分页?这是我用来通过首字母获取帖子的 wordpress 模板中的代码。我只想要 10 页。

$postids=$wpdb->get_col($wpdb->prepare("
SELECT      ID
FROM        $wpdb->posts
WHERE       SUBSTR($wpdb->posts.post_title,1,1) = %s
ORDER BY    $wpdb->posts.post_title",$first_char)); 

if ($postids) {
$args=array(
  'post__in' => $postids,
  'post_type' => 'post',
  'post_status' => 'publish',
  'posts_per_page' => -1,
  'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
 echo 'List of Posts Titles beginning with the letter '. $first_char;
  while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
    <?php
  endwhile;
}
wp_reset_query();  // Restore global post data stomped by the_post().
}
?>

我知道我们可以控制数字。的帖子。但是如何分页? 通常在 wordpress 模板中的普通循环中,它的工作原理是这样的

<?php if ( $wp_query->max_num_pages > 1 ) : ?>
    <div id="nav-above" class="navigation">
        <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&lt;&lt;</span> Show More', 'twentyten' ) ); ?></div>
        <div class="nav-next"><?php previous_posts_link( __( 'Show Previous <span class="meta-nav">&gt;&gt;</span>', 'twentyten' ) ); ?></div>
    </div><!-- #nav-above -->
<?php endif;  ?>

但在这种情况下它不起作用。

【问题讨论】:

    标签: pagination wordpress


    【解决方案1】:

    这里有一个应该有帮助的例子:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $sticky=get_option('sticky_posts');
    $args=array(
       'cat'=>3,
       'caller_get_posts'=>1,
       'post__not_in' => $sticky,
       'paged'=>$paged,
       );
    query_posts($args);
    ?>
    

    query_posts

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-28
      • 2023-03-29
      • 2015-09-18
      • 1970-01-01
      • 2021-07-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多