我正在为具有多个父网页的网站设置博客列表模板,我需要在整个网站上使用此网页模板,各个网页都需要有自己的博客列表页面。根据父类别调用相关帖子。
即:
食物(网站主页)
水果(父母页面)
蔬菜(父母页面)
我的问题是没有调用每个正确父类别的帖子。我收到了所有帖子。
我已经设置了这样的代码:非常感谢提前。
<div id="bloglistings">
<?php wp_reset_query(); ?>
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$current_cat = intval( get_query_var('cat') );
$args = array(
'post_type' => 'post',
'paged' => $paged,
'posts_per_page' => 6,
'order' => 'DESC',
'orderby' => 'ID',
);
$wp_query = new WP_Query( $args );
if ( $wp_query->have_posts() ) : ?>
<div class="row">
<?php $count=0; ?>
<?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<div class="span6">
<div class="media feature one">
<a class="pull-left" href="<?php the_permalink(); ?>">
<?php echo get_the_post_thumbnail($page->ID, 'thumbnail', array('class' => 'img-circle')); ?>
<img class="hoverimage" src="<?php echo get_template_directory_uri(); ?>/img/icon-read-bloglistings.png" alt="">
</a>
<div class="media-body">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p class="date"><?php the_time('F j, Y'); ?></p>
<p><?php
$my_excerpt = get_the_excerpt();
if ( $my_excerpt != '' ) {
// Some string manipulation performed
}
echo $my_excerpt; // Outputs the processed value to the page
?>
</p>
</div>
</div>
</div>
<?php $count++; ?>
<?php if ($count==2 ||$wp_query->found_posts==0) :
echo '</div><div class="row">';
?>
<?php $count=0; ?>
<?php endif; ?>
<?php endwhile; ?>
<?php else : ?>
<h2>Sorry but there are no posts.</h3>
<?php endif; ?>
<!-- PAGINATION -->
<div class="pagination">
<ul>
<li>
<?php
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big
) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages,
) );
?>
</li>
</ul>
</div>
<?php wp_reset_query(); ?>
</div><!-- /.row -->
</div><!--/bloglistings-->
答案 0 :(得分:0)
尝试将类别添加到查询中。
替换它:
$args = array(
'post_type' => 'post',
'paged' => $paged,
'posts_per_page' => 6,
'order' => 'DESC',
'orderby' => 'ID',
);
与
$args = array(
'post_type' => 'post',
'category__in' => array( $current_cat ),// category was missing here
'paged' => $paged,
'posts_per_page' => 6,
'order' => 'DESC',
'orderby' => 'ID',
);