[Resolved] Custom post type portfolio – show categories

Home Forums Support [Resolved] Custom post type portfolio – show categories

Home Forums Support Custom post type portfolio – show categories

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
  • #181522
    Susanne Friedrich

    Hi again Tom,
    I am deeply into making GP and especially the blog add-on work for custom post types and in particular portfolio.
    I am using the portfolio post type plugin, and the masonry layout and added this to my child theme functions to make the masonry layout work.
    `add_filter( ‘generate_blog_masonry’,’generate_adjust_masonry’ );
    function generate_adjust_masonry( $masonry )
    if ( is_post_type_archive( ‘portfolio’ ) )
    $masonry = ‘true’;
    return $masonry;


    But now I find that the archive and the single does not show my categories or my tags or any of the meta.
    This is visible in the regular posts, which uses the same archive.php template. What do I have to add to a child-theme archive-portfolio.php to make the categories and tags show?
    Thanks for your awesome work!

    • This topic was modified 5 years, 4 months ago by Susanne Friedrich.
    Lead Developer
    Lead Developer

    Hi Susanne,

    Those functions are built to only display within the “post” post type to prevent them from showing up in WooCommerce etc..

    You can adjust this using these functions: https://gist.github.com/generatepress/4084f46ab0bd1c9f8c9e

    The second function for generate_posted_on() will work in GP 1.3.29 and onwards.

    Susanne Friedrich

    Hi Tom, thanks for your advice.
    I tried to put these functions into my functions.php file of my child theme, but it did not make the metatags show up.Is there anything else I am missing?

    Lead Developer
    Lead Developer

    Can you link me to the page where they’re supposed to be showing up?

    Susanne Friedrich

    Hi Tom, yes here is the dev url: http://technifex.dreamhosters.com/portfolio/
    I want them to show up in the archive and in the single

    Lead Developer
    Lead Developer

    Ah, I neglected to remove an important part from generate_posted_on().

    Go into /inc/template-tags.php and find the generate_posted_on() function.

    Then remove this from the top of the function:

    if ( 'post' !== get_post_type() ) 

    That should display the date for you.

    For the categories, I think custom post types use different functions to display taxonomy information, so you would have to add your own functions in there: https://codex.wordpress.org/Function_Reference/get_the_term_list

    Susanne Friedrich

    Hi Tom, Remember me?

    I just wanted to report back that I have finally succeeded in doing all I needed with the Portfolio custom post type and thought I’d share it here with people who want to do the same:

    My quest was to show both categories and tags for masonry portfolio posts and make it possible to filter the posts by category.
    I also wanted to be able to show the current category, but was frustrated that I got the category posts in the generic archive template, not the portfolio template. Here’s how I made it work:

    In my child theme I created an archive-portfolio.php template and a content-portfolio.php template.
    In the archive-portfolio template I hardcoded the page title like so
    <h1 class="page-title">Portfolio</h1>
    (There is probably a more elegant way to do it, but it served the purpose for my needs.)

    In content-portfolio.php I added this to show the tags (thanks for pointing me in that direction):
    <?php echo get_the_term_list( $post->ID, 'portfolio_tag', 'tags: ', ', ' ); ?>

    To show the categories I created a custom menu for my portfolio categories and added this in the header of archive-portfolio.php:
    <? wp_nav_menu( array( 'theme_location' => 'portfolio-menu' ) ); ?>

    Now the great thing I discovered was that I could duplicate the portfolio-archive.php and name it taxonomy.php and then I would get my category posts displayed with the Portfolio title instead of the archive title and keep my custom menu in the header. Not only that, but the custom menu for portfolio categories identified the current link item (category), so that I can style it to stand out and serve as a page title. Such a simple solution to something that I just could not figure out for the longest time!
    Hope it will be useful for people who want to do something similar and thank you so much for all your help and support during the long incubation. Will post the site link when we launch

    Lead Developer
    Lead Developer

    Thanks so much for posting the solution! I’m glad you got it all sorted 🙂

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.