我想在自定义页面中使用分页自定义发布。我有自定义posts.php页面,我在其中编写代码
<?php
function designs_theme_custom_post() {
register_post_type( 'logo-portflio',
array(
'description' => 'logo-portflio Post Type',
'show_ui' => true,
'menu_position' => 4,
'exclude_from_search' => true,
'labels' => array(
'name' => __( 'logo-portflio Items' ),
'singular_name' => __( 'portflio Item' ),
'add_new' => __( 'Add New logo portflio Item' )
),
'public' => true,
'supports' => array('title', 'editor', 'custom-fields', 'excerpt', 'thumbnail'),
'has_archive' => true,
'rewrite' => array('slug' => 'logo-portflio'),
));
}
add_action('init', 'designs_theme_custom_post');
?>
并将logo-portfolio.php页面中的帖子称为
`<div class="portfolio">
<ul class="items col4 border">
<?php
global $post;
$args = array( 'posts_per_page' => 3, 'post_type'=> 'logo-portflio');
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<?php
$portfolio_large = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'portfolio-large' );
?>
<!-- /.filter -->
<li class="item thumb">
<figure class="icon-overlay icn-enlarge"><a href="<?php echo $portfolio_large[0]; ?>" class="fancybox-media" data-rel="portfolio"><?php the_post_thumbnail('portfolio-thumb'); ?> </a>
</figure>
<div class="bordered no-top-border">
<div class="info">
<h3 class="post-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<p><?php the_excerpt(); ?></p>
</div>
</div>
</li>
<!-- /.items -->
<?php endforeach; ?>
</ul>
</div>`
我现在要做的是在自定义page.plase中添加Pagination到自定义帖子类型帮我一个....
答案 0 :(得分:1)
请尝试以下代码
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$loop = new WP_Query(
array(
'post_type' => 'logo-portflio',
'post_status' => 'published',
'paged' => $paged,
'posts_per_page' => 3,
'orderby' => 'menuorder',
'caller_get_posts' => 1
)
);
?>
在循环后通过帖子添加以下内容:
<?php
if ($loop->have_posts()) :
while ( $loop->have_posts()) : $loop->the_post();
?>
<!-- Your post-displaying code here... -->
<?php endwhile; ?>
<?php
if(function_exists('wp_pagenavi')){
wp_pagenavi();
}
?>
<?php else : ?>
<?php echo 'not post exits'; ?>
<?php endif; ?>