• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Different templates for different categories?

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Different templates for different categories?

This topic is: resolved

Tagged: categories, custom templates, generate, genesis

  • This topic has 13 replies, 3 voices, and was last updated 9 years, 3 months ago by Brad Dalton.
Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • December 4, 2013 at 11:50 am #76993
    styzer
    Participant

    Hi all,

    I'm working with the Generate theme. I need to create customized templates for different categories. I used to be able to use a special Genesis header coding, but it's giving me errors this time around.

    This is the code I used before:

    
    do_action( 'genesis_doctype' );
    do_action( 'genesis_title' );
    do_action( 'genesis_meta' );
    
    <?php if(is_category(9)){?>
    <link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri(); ?>/style_educate.css" type="text/css" media="screen" />
    <?php }elseif(is_category(6)){?>
    <link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri(); ?>/style_advocate.css" type="text/css" media="screen" />
    <?php }elseif(is_category(3)){?>
    <link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri(); ?>/style_celebrate.css" type="text/css" media="screen" />
    <?php }elseif(is_category(4)){?>
    <link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri(); ?>/style_connect.css" type="text/css" media="screen" />
    <?php }else{?>
    <link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri(); ?>/style.css" type="text/css" media="screen" />
    <?php }
    

    The error refers to the first line starting with <?php if(is_category(9)){?>

    Has something changed in the Genesis framework which keeps me from using this now?

    Thanks for any help!

    http://musicmakesus.ca/neweng/
    December 5, 2013 at 12:19 pm #77256
    Brad Dalton
    Participant

    Do these still work on HTML 5 themes?:

    do_action( 'genesis_title' );
    do_action( 'genesis_meta' );
    

    Tutorials for StudioPress Themes.

    December 5, 2013 at 1:44 pm #77271
    styzer
    Participant

    Not sure, Brad, maybe I'll try to take these out and see?

    December 12, 2013 at 11:24 pm #78733
    styzer
    Participant

    No joy, here... I found this on StudioPress though: http://my.studiopress.com/snippets/custom-body-class/

    
    Add body class to a category page with an ID of 1:
    
    <?php
    //* Do NOT include the opening php tag
     
    //* Add custom body class to the head
    add_filter( 'body_class', 'sp_body_class' );
    function sp_body_class( $classes ) {
    if ( is_category( '1' ))
    $classes[] = 'custom-class';
    return $classes;
    }
    
    view raw category-1.php  

    I would like to be able to use this, then. However, I need clarity:

    1- do I create a new file?
    2- do I edit style.css?
    3- any setting I need to do in the dashboard?

    Thank you ANYONE! I've been stumped for days and I'm getting very depressed, the more I try to figure it out, the more I feel something is wrong with my brain...

    ANdre

    December 13, 2013 at 12:33 am #78745
    Summer
    Member

    That snippet would go in your functions.php.

    You would change 'custom-class' to whichever custom body class you'd want to use, say, from your code above you'd use 'educate', and then you'd add that as a class to the "body" section of your style.css, using the code from your style-educate.css,

    I think it's possible to enqueue that style-educate.css as a separate css file, but I'm not sure about the best practice method of that at the moment.


    WordPress / Genesis Site Design & Troubleshooting: A Touch of Summer | @SummerWebDesign
    Slice of SciFi | Writers, After Dark

    December 13, 2013 at 2:56 am #78757
    Brad Dalton
    Participant

    All that does is generate a unique body class conditionally which will help if you want to style each category archive differently.

    You don't need separate style sheets however you can add them using this code.

    Otherwise, you can create category archive templates which also include a unique body class.


    Tutorials for StudioPress Themes.

    December 13, 2013 at 3:26 am #78764
    Brad Dalton
    Participant

    Here's a good explanation of creating category archives however you wouldn't use this code in this post for genesis http://codex.wordpress.org/Category_Templates


    Tutorials for StudioPress Themes.

    December 13, 2013 at 10:29 am #78813
    Summer
    Member

    Brad, what would be considered the "best practice" method for maintaining a separate css file for customizations, for tinkerers who'd really love to update theme versions without losing customizations, just because we like to play so much? 🙂


    WordPress / Genesis Site Design & Troubleshooting: A Touch of Summer | @SummerWebDesign
    Slice of SciFi | Writers, After Dark

    December 13, 2013 at 12:21 pm #78847
    styzer
    Participant

    OK, getting somewhere!

    I inserted this in style.css:

    /* EDUCATE pages - different background */
    .educate-class {
        background-color: #84b855;
    	}

    And this in functions.php:

     //* Add custom body class to the head
    add_filter( 'body_class', 'sp_body_class' );
    function sp_body_class( $classes ) {
    	if ( is_page( '4' ))
    		$classes[] = 'educate-class';
    		return $classes;
    }

    Now something VERY strange happens. The new background color will ONLY show if I reduce my page to a certain size, like 50%. Only then can I see the new background color as a stripe on each side.

    December 13, 2013 at 12:37 pm #78852
    styzer
    Participant

    Looks like I also had a bit of a mess on my hands: of the 15 categories that were on this site, only 3 of them have any post, plus the uncategorized category. So 4 categories. The rest have no use. So in fact, I'm not working with categories templates, but pages templates.

    December 13, 2013 at 12:43 pm #78855
    styzer
    Participant

    If I select the "landing" template in "page edit," I see a stripe of green color on top, but no header... I'll keep playing with this and see. If anyone has any clue...

    http://musicmakesus.ca/neweng/educate/

    Regards,

    Andre

    December 13, 2013 at 2:46 pm #78883
    styzer
    Participant

    I was able to figure this out with the help of my nephew. I'll post the solution later!

    http://musicmakesus.ca/neweng

    Andre

    December 14, 2013 at 12:41 pm #79084
    styzer
    Participant

    OK, so here is the solution I applied:

    1- In functions.php, I added this code near the top, right under:

    //* Child theme (do not remove)
    define( 'CHILD_THEME_NAME', 'Generate Theme' );
    define( 'CHILD_THEME_URL', 'http://my.studiopress.com/themes/generate' );
    define( 'CHILD_THEME_VERSION', '1.0.2' );
    $content_width = apply_filters( 'content_width', 570, 450, 880 );
    

    Here is the code I inserted:

    //* Add custom body class to the head
    add_filter( 'body_class', 'sp_body_class' );
    function sp_body_class( $classes ) {
     global $post;
     if ( is_page( '4' ) || (isset($post->post_parent) && $post->post_parent == 4)){
       $classes[] = 'educate-class';
      }
    
     if ( is_page( '12329' ) || (isset($post->post_parent) && $post->post_parent == 12329)){
       $classes[] = 'advocate-class';
      }
    
     if ( is_page( '12330' ) || (isset($post->post_parent) && $post->post_parent == 12330)){
       $classes[] = 'celebrate-class';
      }
    
     if ( is_page( '12331' ) || (isset($post->post_parent) && $post->post_parent == 12331)){
       $classes[] = 'connect-class';
      }
    
      return $classes;
    }

    2- I created the 4 classes to insert in my style.css file AT THE VERY BOTTOM of the file, after everything (Generate theme has a double closing }, so right AFTER that). Here is what it looks like :

    
    /* EDUCATE pages - different background */
    .educate-class {
        background: #84b855;
    	}
    
    .educate-class #inner {
     background-color: #84b855;
    }
    
    .educate-class #wrap {
     background-color: #6a9544;
    }
    
    /* ADVOCATE pages - different background */
    
    .advocate-class {
        background: #f28c4d;
    	}
    
    .advocate-class #inner {
     background-color: #f28c4d;
    }
    
    .advocate-class #wrap {
     background-color: #dc5b0b;
    }
    
    /* CELEBRATE pages - different background */
    
    .celebrate-class {
        background: #e09ddc;
    	}
    
    .celebrate-class #inner {
     background-color: #e09ddc;
    }
    
    .celebrate-class #wrap {
     background-color: #cd66cc;
    }
    
    /* CONNECT pages - different background */
    
    .connect-class {
        background: #c2afe6;
    	}
    
    .connect-class #inner {
     background-color: #c2afe6;
    }
    
    .connect-class #wrap {
     background-color: #673bb8;
    }

    3- I select the appropriate parent for each child-page in the dashboard, so they will display the specific color.

    Voila! Hope this helps someone else, this is by far the simplest and most effective way I've seen of doing it.

    Regards,

    Andre

    December 15, 2013 at 12:13 am #79189
    Brad Dalton
    Participant

    Thanks Andre


    Tutorials for StudioPress Themes.

  • Author
    Posts
Viewing 14 posts - 1 through 14 (of 14 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble