简体   繁体   English

Wordpress中的类别页面

[英]Category page in wordpress

I am developing a custom wordpress theme ( first time) , I have created below files and they work fine by following this tutorial. 我正在开发自定义的wordpress主题(第一次),我已经创建了以下文件,并且通过遵循教程可以正常工作。

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

Now issue is when I click on a category name at home page it show me 404 error, I tried to create category.php but still same issue. 现在的问题是,当我单击主页上的类别名称时,它显示404错误,我尝试创建category.php,但仍然是同样的问题。 here is my index.php which I used for 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(); ?>

I have two question: 我有两个问题:

  1. Is it really require to create category.php or can we use index.php for same purpose to show posts from category or tags? 是真的需要创建category.php还是我们可以出于相同目的使用index.php显示类别或标签中的帖子?
  2. If it's require to create category.php, Do I also need to create tags.php and how will I get posts for those? 如果需要创建category.php,是否还需要创建tags.php,我将如何获得这些帖子?

No, it is not required to have category.php file in a WordPress theme. 不,不需要在WordPress主题中包含category.php文件。 You can see following link for finding out template hierarchy in WordPress works. 您可以在WordPress作品中看到以下链接,以了解模板层次结构。

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

You can see that, if there is no category.php file in theme, it ultimately falls back to index.php . 您可以看到,如果主题中没有category.php文件,则最终它会退回到index.php

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

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