Wordpress theming Wordpress类别,获取其所有帖子

Wordpress theming Wordpress类别,获取其所有帖子,wordpress-theming,wordpress,Wordpress Theming,Wordpress,我目前正在为我正在建设的wordpress网站完成我的主题,但我在让我的分类发挥作用方面遇到了问题 如果我的URL是“/category/category name”,我不知道如何循环当前类别,我将如何循环属于类别“category name”的帖子 我在我的模板上执行以下操作 类别:我得到以下输出 类别名称 那么我如何循环浏览这些类别的帖子呢 Category.php <?php get_header(); ?> <article class="content"&g

我目前正在为我正在建设的wordpress网站完成我的主题,但我在让我的分类发挥作用方面遇到了问题

如果我的URL是“/category/category name”,我不知道如何循环当前类别,我将如何循环属于类别“category name”的帖子

我在我的模板上执行以下操作

类别:

我得到以下输出

类别名称

那么我如何循环浏览这些类别的帖子呢

Category.php

<?php get_header(); ?> 
    <article class="content">   
        <section class="top">       
            <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>         

            <?php endwhile; else: ?>        
                 <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>      
            <?php endif; ?>
        </section>  
        <section class="middle">        
        </section> 
     </article> 
     <?php get_footer(); ?>

类别:

标签:


因此,page-news.php是我的新闻文章所在的地方,用户可以使用

生成的链接获取类别,您可以在您的内部使用该链接来循环帖子

基于上述代码,我认为您没有在
category.php
中输出任何内容
the_post()
不会回显任何内容。它只是将下一条记录放入
$post
。试试这个

<?php
get_header();
$cat = get_category(get_query_var("cat"));
var_dump($cat); //make sure that there really is a valid category and it's the right one
?>

<h1 class="page-title"><?php echo $cat->name?></h1>
<?php 
if (have_posts()) {
    while (have_posts()){
        the_post();
        <h2><?php the_title()?></h2>
        <?php the_content()?>
      <?php
      }
} else {
    ?>
    <p>No posts found!</p>
   <?php
}
?>


<?php
get_footer();
?>

模板文件的文件名是什么?如果它是
category.php
,那么属于该类别的帖子已经加载,您可以循环浏览它们。它是category.php,我认为现在可以执行以下操作了吗
看起来很奇怪,后来又出现了没有帖子的情况…(1)您确定该类别中有帖子,并且(2)您确定正在编辑的模板是正在使用的模板吗?(在顶部添加“This is my template”(这是我的模板)以检查后者。当我的循环返回到“对不起,没有帖子”时,请确定正确的模板。),当我通过post中的category链接进入页面时,该类别中肯定有帖子,因此它肯定是一个有效的类别,并且该类别中肯定有帖子,正如在管理区域中,我可以看到在该类别旁边有一篇新闻文章,但是在category.php中有帖子
<?php
get_header();
$cat = get_category(get_query_var("cat"));
var_dump($cat); //make sure that there really is a valid category and it's the right one
?>

<h1 class="page-title"><?php echo $cat->name?></h1>
<?php 
if (have_posts()) {
    while (have_posts()){
        the_post();
        <h2><?php the_title()?></h2>
        <?php the_content()?>
      <?php
      }
} else {
    ?>
    <p>No posts found!</p>
   <?php
}
?>


<?php
get_footer();
?>
<p class="tags"><?php the_category()?></p>