WordPress.org

Support

Support » Themes and Templates » [Resolved] Displaying Category-Specific Post Formatting

[Resolved] Displaying Category-Specific Post Formatting

  • criticalxnature
    Member

    @criticalxnature

    I’m new to WordPress and what I’m looking to do is display posts differently depending on their category – including any subcategories beneath.

    I’ve seen the ‘testing if a post is in a descendant category’ function but I can’t seem to get it to work how I want it to without getting a server error. Ideally, I would be looking to modify the category.php to something like this after get_header:

    <?php
    if ( in_category( 'fruit' ) || post_is_in_descendant_category( 11 ) ) {
    	include 'cat-fruit.php';
    } elseif ( in_category( 'vegetables' ) || post_is_in_descendant_category( 12 ) ) {
    	include 'cat-vegetables.php';
    } else {
    	// Continue with normal Loop
    	if ( have_posts() ) : while ( have_posts() ) : the_post();
    	// ...
    }
    ?>

    I realise the code is most likely wrong, but its only to try and show what I’m trying to do.

    Posts within ‘fruit’ and/or its subcategories would be displayed as stated in cat-fruit.php. Posts within ‘vegetables’ and/or its subcategories would be displayed as stated in cat-vegetables.php, and anything else would be displayed as the default.

    I’m using a child of Twenty Twelve, and have pasted the function from the codex into the child’s functions.php.

    Any help would be much appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] Displaying Category-Specific Post Formatting’ is closed to new replies.