Viewing 2 replies - 1 through 2 (of 2 total)
  • There is a plugin which already does this https://wordpress.org/plugins/add-category-to-pages/

    But if you wanted to code your own solution then I would approach your problem from a different angle. This would be work out how the theme is getting the pages that have the portfolio-item template and then copy/modify that code to apply to posts of certain categories.

    You would need to:-

    a) Create a child theme so that when the theme you are modifying get’s updated your changes are not overwritten. See https://codex.wordpress.org/Child_Themes

    b) Inspect the code which gets the pages with the portfolio-item, copy, paste & modify as necessary and add your modified code to the child theme functions.php.

    c) Override the template which is displaying the thumbnails by adding a template with the same name in your child theme, and then modify your child theme template to use your modified function.

    The reason I would take this approach is that by using child themes it gives you greater flexibility.

    If you have a lot of pages and want to change which categories you apply your logic to, with your initial proposal you will have to go through each page to change the category. Whereas you could add applicable categories over time, so that the thumbnail logic could apply to several categories.

    The initial coding will be slightly less work I think because you are re-using more of the existing code, and existing WordPress functionality.

    Thread Starter cpabell

    (@cpabell)

    I’d prefer to go at it with my own code. Great idea with the child themes! I wasn’t aware of them until now. Thanks a bunch, I will definitely give it a try!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Questions about Metadata’ is closed to new replies.