WordPress.org

Ready to get started?Download WordPress

Forums

Sub-Category templates not working when no /category/ base slug used (10 posts)

  1. diesel12
    Member
    Posted 5 years ago #

    I am using categories and sub-categories to organize my content and use a %category%%post-name% permalink structure. This means that a typical url for a post in a sub-category is: site.com/category/category1/subcategory1/postname . Since my url's are longer then I would like with this type of url structure, I removed the /category/ category base slug (not the %category% from the permalink url) from the URL via the permalink settings page to get a typical subcategory url of site.com/category1/subcategory1/postname/ (notice the /category/ immediately after site.com/ is no longer present as is the case with any category when /catgeory base is used). This has created the following issue: my categories utilize my category.php template, but my sub-categories do not, they use the index.php template..... this means that sub-categories are not excerpts as they would be if they used my category template, among other changes that I have implemented in my category template....... this issue goes away if I simply add back the /category/ category base to my url structure, but this means my already long url's get even longer.... example: http://www.site.com/category/category1/subcategory1/nameofppost/ as opposed to http://www.site.com/category1/subcategory1/nameofppost/

    Any feedback appreciated!

  2. diesel12
    Member
    Posted 5 years ago #

    Sorry if I wasn't clear, any feedback appreciated on how I can enable to have my sub-categories recognize the category.php template when I disable the /category/ category base slug... thanks!

  3. iridiax
    Member
    Posted 5 years ago #

    Do NOT use just /%postname%/ for your permalinks, you'll only have problems. If a category slug is making your urls too long, shorten the Category Slug in Dashboard -> Manage -> Categories.

  4. diesel12
    Member
    Posted 5 years ago #

    To clarify: I use %category%/%postname& for my default permalink structure. I was referring to removing the %category% category base slug as shown at bottom of permalink options page (the default /category/ that is present in url every time you show a category) so a default url is : http://www.site.com/category1/postname/ as opposed to the default of http://www.site.com/category/category1/postname with the /category/ base slug

    hope this helps...

  5. diesel12
    Member
    Posted 5 years ago #

    Hmmm.... if I remove the category base by editing rewrite.php in wp-includes by removing category/ (as opposed to permalinks options page where you would put /. in category base to remove category base altogether) my sub categories do utilize the category.php template correctly, but the single page permalinks do not work....... so if you click on a post title to read the article and or comments..... you get a 404 .....

  6. iridiax
    Member
    Posted 5 years ago #

    If you leave Category base blank, it defaults to category, so how are you removing it? I would strongly recommend that you do not try to do this.

  7. diesel12
    Member
    Posted 5 years ago #

    I screwed this up in previous references, disregard postname in any above url references....I am referring to category and subcategory url's and accidentally included /postname when I shouldn't have...

  8. diesel12
    Member
    Posted 5 years ago #

    I'm removing the category base though the permalinks options page which give you the ability to change the category and tag bases at the bottom of the page.... if you use /. as your category base it removes the /category/ base or you can change the base to whatever word you choose....

  9. diesel12
    Member
    Posted 5 years ago #

    The goal isn't to create more trouble then its worth, which is probably the end result here... so if the category base must stay...then stay it will.... :)

  10. Ivovic
    Member
    Posted 5 years ago #

    /. is not the right way to go about this, there are plugins which can remove the category base, but they require you to have a static feature in your permalink slugs... like prefix-%postname%, or %postname%.html for instance, so that the system can tell the difference between posts and categories.

    I will warn you though, I've experimented with %category%/%postname% quite heavily, and I can tell you that any pages listing multiple posts will be *MUCH* higher in queries, because each time the permalink is called, wordpress will have to query the database to trickle-down the parent/child relationship between categories in order to generate the permalink.

    this can really overload your site if you're not careful.

    ultimately? not worth it. You can use a really short category base to get around most issues, and if you don't like date based permalinks, then set your structure to /articles/%postname% - which allows you to make an /articles/ page to lay out all your categories in a sitemap format.

Topic Closed

This topic has been closed to new replies.

About this Topic