2013-08-12 24 views
0

我已經在小部件中顯示自定義帖子類型。現在我想在最後添加分頁。因爲我的自定義帖子類型中有超過10個帖子。分頁我的自定義帖子類型的小工具

<ul class="posts-list"> 
<?php if (have_posts()) : ?> 
<?php 

global $post; 
    $cats = get_the_category(); 
    $cat_name = $cats[0]->name; 
    $args = array(
    'posts_per_page' => 10, 
    'offset'   => 0, 
    'category'   => $cat_name, 
    'orderby'   => 'post_date', 
    'order'   => 'DESC', 
    'post_status'  => 'publish', 
    'suppress_filters' => true); 

$previous_post = get_posts($args); 
foreach ($previous_post as $post) : 
    setup_postdata($post); ?> 
    <li> 
     <h5><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5> 
     <p>posted on <?php the_time(' F jS, Y') ?> by <?php the_author(); ?></p> 
     <p>Posted in <?php echo $cat_name->name; $cat_name = get_the_category($post->ID); ?></p>  
    </li> 
<?php endforeach; 
wp_reset_postdata(); ?> 
<?php endif; ?> 
</ul> 

回答

1

試試這個和'post_type' => 'your custom post type name'

<ul class="posts-list"> 
<?php if (have_posts()) : ?> 
<?php 

global $post; 
$paged1 = isset($_GET['paged1']) ? (int) $_GET['paged1'] : 1; 
    $cats = get_the_category(); 
    $cat_name = $cats[0]->name; 
    $args = array(
    'posts_per_page' => 10, 
    'offset'   => 0, 
    'category'   => $cat_name, 
    'orderby'   => 'post_date', 
    'paged'   => $paged1, 
    'post_type' => 'your custom post type name' 
    'order'   => 'DESC', 
    'post_status'  => 'publish', 
    'suppress_filters' => true); 

$previous_post = get_posts($args); 
foreach ($previous_post as $post) : 
    setup_postdata($post); ?> 
    <li> 
     <h5><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5> 
     <p>posted on <?php the_time(' F jS, Y') ?> by <?php the_author(); ?></p> 
     <p>Posted in <?php echo $cat_name->name; $cat_name = get_the_category($post->ID); ?></p>  
    </li> 
<?php endforeach; 
?> 
<?php endif; 

$pag_args1 = array(
    'format' => '?paged1=%#%', 
    'current' => $paged1, 
    'total' => $previous_post->max_num_pages, 
    'add_args' => array('paged1' => $paged1) 
); 
echo paginate_links($pag_args1); 
wp_reset_postdata(); ?> 

</ul> 
輸入您的自定義後類型的名稱
相關問題