繁体   English   中英

Wordpress中的类别页面

[英]Category page in wordpress

我正在开发自定义的wordpress主题(第一次),我已经创建了以下文件,并且通过遵循教程可以正常工作。

index.php
header.php
footer.php
single.php
sidebar.php

现在的问题是,当我单击主页上的类别名称时,它显示404错误,我尝试创建category.php,但仍然是同样的问题。 这是我用于category.php的index.php

<?php get_header(); ?>
// other html stuff and loop
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php endwhile;?>
<?php endif; ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

我有两个问题:

  1. 是真的需要创建category.php还是我们可以出于相同目的使用index.php显示类别或标签中的帖子?
  2. 如果需要创建category.php,是否还需要创建tags.php,我将如何获得这些帖子?

不,不需要在WordPress主题中包含category.php文件。 您可以在WordPress作品中看到以下链接,以了解模板层次结构。

https://developer.wordpress.org/themes/basics/template-hierarchy/#category

您可以看到,如果主题中没有category.php文件,则最终它会退回到index.php

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM