1

I'm not sure if this is 'normal' but on my WP install the actual directory for 'category' throws a 404 error.

So, for example, if I had a category called 'apples' then every post or page associated with the 'apples' category has this URL string:

my-site.com/category/apples/ 

The above for me loads fine.

However, if I remove the 'apples' from the URL then a 404 error is generated, which I am sure is correct, or should there be an index page or other?

The reason I am asking about this is because I created some custom Taxonomy called 'US States' which works like this:

my-site.com/us-states/florida < loads great with archive

my-site.com/us-states/ < Error 404

Is there anyway to make the HOME of the actual taxonomy a templated page or other?

Thanks

  • 2
    This is the standard behaviour, yes. By default all URLs in WordPress are lists of posts or single posts. There are no posts that it would make sense to display at such a URL. – Jacob Peattie Apr 8 '19 at 5:02
2

Yes, it's normal behavior. WordPress uses a set of rewrite rules to process requests. Here are the rules that will match requests related to categories:

[category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?category_name=$matches[1]&feed=$matches[2]
[category/(.+?)/(feed|rdf|rss|rss2|atom)/?$] => index.php?category_name=$matches[1]&feed=$matches[2]
[category/(.+?)/page/?([0-9]{1,})/?$] => index.php?category_name=$matches[1]&paged=$matches[2]
[category/(.+?)/?$] => index.php?category_name=$matches[1]

As you can see, all of them require, that the request is longer than /category/.

And it makes sense.

  • category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/ - will match the feed for category
  • [category/(.+?)/(feed|rdf|rss|rss2|atom)/ - is a shorter URL for feed
  • category/(.+?)/page/?([0-9]{1,})/ - is support for pagination
  • category/(.+?)/ - is just category listing (first page)

So all of the URLs above are related to given term in this taxonomy and you know which term, because it is defined in URL.

On the other hand, what should be displayed when you go to /category/? No term is defined, so you can't select any one of them. So should it show you all posts on your site? (Blog index already does it).

Sometimes it makes sense to show the list of categories on such URL, but it isn't a common practice.

You can always add your custom rewrite rule to process such requests.

-1

You can create template files for each level of the category tree. Also for the one you mentioned. If you create a template called category.php or archive.php WordPress will load it on this level. Place it in your themes root folder.

Find more detailed info on the view hierarchy here: https://developer.wordpress.org/themes/basics/template-hierarchy/#examples

  • I'm not entirely sure that this is the case. Putting category.php template won't show change what is showing on example.com/category/ url. – Krzysiek Dróżdż Apr 8 '19 at 4:58
  • I see....so if I create that template then will it load the posts in a loop? I'd rather it load a blank template for me to place other content on? I guess the answer is that of course I can create any template I wish! – henry Apr 8 '19 at 4:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.