• hi there – please excuse me if this is a silly question. I was asked to look at a portfolio theme, and the client would like the titles of the portfolio items to display only for those items which are descendants of the category ‘videos’. I am just learning PHP, so I’m not quite sure what to add to the existing code that builds the portfolio page.

    (The portfolio theme has an admin panel where you can set the post titles to display for all or none portfolio items, hence $options below.)

    Here is the code for that:

    <?php
    
    			//unless disabled show portfolio item title
    
                 if ($options['disable_portfolio_title'] == false ) { ?>
    
                  <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
    
               <?php } ?>

    I am hoping that I can add something to that if statement that will filter the results, and only show the titles for the posts in the video category and its descendants. Any help would be greatly appreciated. I’ve been searching through the codex but haven’t yet had any success.

    Also, please let me know if you need to see more code.

    Thank You.

Viewing 2 replies - 1 through 2 (of 2 total)
  • [mod: please mark any directly posted code – see forum guidelines – the code below is already corrupted]

    if ($options[‘disable_portfolio_title’] == false ) {
    foreach( get_the_category() as $category ) {
    if( cat_is_ancestor_of( category_id, $category ) ) { ?>
    <h4>“><?php the_title(); ?></h4>
    <?php }
    }
    } ?>

    Paste the id of the category videos instead of category_id.

    Thread Starter Max

    (@panmac)

    Hi Fire Truck –

    Thanks so much for this. When I drop the code in with the proper category id, it removes all the titles for all categories – which makes me think these categories aren’t in the normal category table . Is that possible? These portfolio items are custom post types – could that be the problem?

    Thank you for any further suggestions.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘display post titles only for descendants of a certain category’ is closed to new replies.