【发布时间】:2014-10-30 22:35:59
【问题描述】:
我一直在试图弄清楚如何将我的自定义帖子类型分类分解为页面,但我遇到了麻烦。
如果有人能告诉我如何使这项工作变得很棒,我希望使档案每 6 个帖子分成新页面。
这是我档案的当前布局:
<?php
// Exit if accessed directly
if( !defined( 'ABSPATH' ) ) {
exit;
}
/**
* News Archive Template
*/
global $wp_query;
$wp_query = new WP_Query( array ('posts_per_page' => 6, 'post_type' => 'news', 'post_status' => array('publish'),
'tax_query' => array(
array(
'taxonomy' => 'news_category',
'field' => 'slug',
'terms' => array( $wp_query->query['news_category']),
'include_children' => true,
'operator' => 'IN'
),
)));
get_header(); ?>
<div id="content-archive" >
<?php if( have_posts() ) : ?>
<?php while( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if( is_single() ): ?>
<h1 class="entry-title post-title"><?php the_title(); ?></h1>
<?php else: ?>
<h2 class="entry-title post-title"><a href="<?php the_title(); ?></a></h2>
<?php endif; ?>
<div class="post-meta">
<?php
printf( __( '<span class="%1$s">Posted on </span>%2$s<span class="%3$s"> by </span>%4$s', 'responsive' ),
'meta-prep meta-prep-author posted',
sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><time class="timestamp updated" datetime="%3$s">%4$s</time></a>',
esc_url( get_permalink() ),
esc_attr( get_the_title() ),
esc_html( get_the_date('c')),
esc_html( get_the_date() )
),
'byline',
sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
get_author_posts_url( get_the_author_meta( 'ID' ) ),
sprintf( esc_attr__( 'View all posts by %s', 'responsive' ), get_the_author() ),
esc_attr( get_the_author() )
)
);
?>
</div></div><!-- end of .post-meta -->
<!-- end of .post-entry -->
</div><!-- end of #post-<?php the_ID(); ?> -->
<?php
endwhile;
else :
echo "No posts here";
endif;
?>
</div>
<!-- end of #content-archive -->
<?php get_footer(); ?>
【问题讨论】:
-
啊!让它工作!谢谢你们的帮助。在没有
$paged = (get_query_var('page')) ? get_query_var('page') : 1;的情况下单独添加'paged' => $paged,似乎有效
标签: php wordpress pagination