我在Wordpress中有一个页面,它是一个博客页面模板。现在我的问题是它显示所有帖子。我只希望它显示分配给某个类别的帖子
我该怎么做?
这是我的blog.php页面:我想你必须在这里编辑它吗?
<?php
/*
Template Name: Blog page
*/
?>
<?php get_header(); ?>
<div class="blog">
<?php
$gogo_select_blog_sidebar_position = get_post_meta($post->ID, 'gogo_select_blog_sidebar_position', true);
$gogo_blog_link_text = get_post_meta($post->ID, 'gogo_blog_link_text', true);
$gogo_blog_link_url = get_post_meta($post->ID, 'gogo_blog_link_url', true);
$gogo_blog_text_no_posts = get_post_meta($post->ID, 'gogo_blog_text_no_posts', true);
?>
<header class="box-headline">
<h4 class="main-headline"><?php the_title(); ?></h4>
</header>
<?php if($gogo_select_blog_sidebar_position=='right-sidebar-blog-template') { ?>
<!--Left content area-->
<div class="blog-holder">
<?php } else { ?>
<div class="blog-holder right">
<?php } ?>
<?php
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('posts_per_page='.$gogo_blog_text_no_posts.'&paged='.$paged);
$postcount = 0;
while ($wp_query->have_posts()) : $wp_query->the_post(); $postcount++;
?>
<!--Begin post content-->
<?php
// The following determines what the post format is and shows the correct file accordingly
$format = get_post_format();
get_template_part( '/lib/includes/post-formats/'.$format );
if($format == '')
get_template_part( '/lib/includes/post-formats/standard' );
?>
<?php if($postcount % 2 == 0) echo "<div class='clearfix'></div>"; ?>
<!--End post content-->
<?php endwhile; ?>
<!--Pagination -->
<?php if (function_exists("pagination")) {pagination();} ?>
<!--End pagination -->
<?php $wp_query = null; $wp_query = $temp;?>
</div>
<!--End left content area-->
<?php if($gogo_select_blog_sidebar_position=='right-sidebar-blog-template') { ?>
<!-- Right content -->
<aside class="sidebar right">
<?php } else { ?>
<aside class="sidebar left">
<?php } ?>
<?php get_sidebar('blog'); ?>
</aside>
<!-- End Right content -->
</div><!-- End .block -->
<?php get_footer();?>
答案 0 :(得分:1)
将您的类别添加到WP_Query字符串:
$wp_query->query('posts_per_page='.$gogo_blog_text_no_posts.'&paged='.$paged . '&category_name=***yourcategory***');