分页不适用于wordpress自定义帖子类型

时间:2014-10-24 05:32:39

标签: wordpress pagination custom-post-type

这是我在wordpress中列出自定义帖子类型帖子所做的代码,但它没有分页,我在这里做的错误可以帮助吗?

<div id="talent-main">
   <?php      
   global $wp_query; 
   $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
   $loop = new WP_Query( array('post_type' => 'talent','posts_per_page' => 2,'paged'=>$paged)); 
   ?>

    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
          <div id="post-<?php the_ID(); ?>" <?php post_class('multiple') ?>>
              <div class="post-image-talent">
                  <a class="post-frame <?php the_ID(); ?>" href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"></a>
                  <?php the_post_thumbnail('video-talent-thumb'); ?>
              </div>
              <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_short_title('', '...', true, '22') ?></a></h2>
          </div> 
    <?php endwhile;?>
    <div class="navigation">   
        <div class="alignleft"><?php previous_posts_link('&laquo; Previous') ?></div>   
        <div class="alignright"><?php next_posts_link('More &raquo;') ?></div>   
    </div>  
</div> <!-- main -->

1 个答案:

答案 0 :(得分:0)

您可以查看以下代码吗?

<?php
global $wp_query;  
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

$loop = new WP_Query(array(
    'post_type'=>'talent',
    'posts_per_page' => 2,
    'paged' => $paged,
)); ?>

<?php if($loop->have_posts()) : ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
          <div id="post-<?php the_ID(); ?>" <?php post_class('multiple') ?>>
              <div class="post-image-talent">
                  <a class="post-frame <?php the_ID(); ?>" href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"></a>
                  <?php the_post_thumbnail('video-talent-thumb'); ?>
              </div>
              <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_short_title('', '...', true, '22') ?></a></h2>
          </div> 
    <?php endwhile;?>          
    <?php 
    $total_pages = $loop->max_num_pages;

    if ($total_pages > 1){

        $current_page = max(1, get_query_var('paged'));

        echo paginate_links(array(
            'base' => get_pagenum_link(1) . '%_%',
            'format' => '/page/%#%',
            'current' => $current_page,
            'total' => $total_pages,
            'prev_text'    => __('« prev'),
            'next_text'    => __('next »'),
        ));
    }
    ?>    
<?php else :?>
<h3><?php _e('404 Error&#58; Not Found', 'No post found'); ?></h3>
<?php endif; ?>
<?php wp_reset_postdata();?>
相关问题