Wordpress 如何使博客页面仅显示某些帖子

Wordpress 如何使博客页面仅显示某些帖子,wordpress,Wordpress,我在Wordpress中有一个页面,它是一个博客页面模板。现在我的问题是它会显示所有的帖子。我只想让它显示分配给某个类别的帖子 我该怎么做 这是我的blog.php页面:我想你必须在这里编辑它,对吗 <?php /* Template Name: Blog page */ ?> <?php get_header(); ?> <div class="blog"> <?php $gogo_select_blog_sidebar_position = g

我在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();?>


将您的类别添加到WP_查询字符串:

$wp_query->query('posts_per_page='.$gogo_blog_text_no_posts.'&paged='.$paged . '&category_name=***yourcategory***'); 

很好,谢谢。谢谢。还有一个问题:我想用Blog页面模板创建另一个页面,但是对于这个页面,我只想显示另一个类别,但是由于它将使用相同的Blog.php页面,我如何为新页面指定另一个类别?请查看,您可能更喜欢使用
category.php
来完成此任务。当然,这取决于你的背景。谢谢。非常感谢你的回答。让它发挥作用。我复制blog.php文件并将其命名为blog2.php。我更改了顶部的模板名称,并使用您提供给我的代码仅显示某个类别的帖子。因此,当我创建一个包含帖子的新页面时,我只需选择正确的模板(这就是在blog.php文件的顶部命名模板名称的地方)