0
votes

I am developing a custom wordpress theme ( first time) , I have created below files and they work fine by following this tutorial.

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. here is my index.php which I used for category.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?
  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?
1
A 404 has nothing to do with your template files. WordPress determines whether or not a request is a 404 before it determines which template file to use. In any case, index.php will act as a catchall if category.php does not exist.Mathew Tinsley

1 Answers

0
votes

No, it is not required to have category.php file in a WordPress theme. You can see following link for finding out template hierarchy in WordPress works.

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.