• 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

Custom layout for posts in a category.

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 › General Discussion › Custom layout for posts in a category.

This topic is: resolved

Tagged: Category post, Custom post, Site layout

  • This topic has 6 replies, 3 voices, and was last updated 13 years, 7 months ago by Jen Baumann.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • December 13, 2012 at 11:07 pm #5167
    robskidmore
    Member

    I've spent two days trying to figure this out.

    What I'm trying to do

    When I put posts in a certain category I want them to be displayed differently.

    The Method

    This is what I have so far. I created my custom template and added it as writing.php. I added the following code to my functions.php. This successfully brought out my custom template but is also added the code from the single.php file. I know because I added code to the single.php and was able to make changes to the post.


    /** Add the custom writing template */

    add_action( 'genesis_after_header', 'minimum_writing_category', 15 );

    function minimum_writing_category() {

    if (in_category ( 'writing')) {

    require_once( get_stylesheet_directory() . '/writing.php' );

    }

    }

     

    My Question

    How do I remove the call to the single.php? I've scoured the interwebz and these forums for hours to no avail.

     

    If someone can help I would greatly appreciate it.

     

    Thanks Rob.

    December 14, 2012 at 9:36 am #5211
    John
    Participant

    Rob,

    Here's how I would do that:

    1. Put your custom template inside a function instead of in writing.php, and remove writing.php all together. In this example I'm calling that function writing_content_template

    2. Add that new function to functions.php, or better yet, to a custom-functions plugin in your mu-plugins directory, which you can create in wp-content if it's not there already. The benefit of mu-plugins is that it stays with the site even if the theme changes.

    3. In single.php add a conditional for that category that removes the post content and replaces it with your custom template. Something like this:

    if( in_category ( 'writing' ) ) {
    remove_action( 'genesis_post_content', 'genesis_do_post_content' );
    add_action( 'genesis_post_content', 'writing_content_template' );
    }

    I haven't tested this specifically with a category, but I have done something very similar with displaying different custom post types with different content templates. And by putting that template in a function you can call it wherever you need it, in multiple page templates, for example.

    John


    John Sundberg | blackhillswebworks.com
    A WordPress developer’s toolbox: Firebug | WordPress Codex | Google 😉

    December 14, 2012 at 9:49 am #5214
    Jen Baumann
    Participant

    That assumes that you copy single.php to the child theme.  Don't edit Genesis single.php.  You could also try it in functions.php and use

    if( is_single() && in_category( 'writing') )

    note that should be && not the html...grrr.

     

    December 14, 2012 at 10:48 am #5224
    John
    Participant

    Jen,

    Right. I was assuming that the modified single.php would be in the child theme directory, but thanks for mentioning that.

    RE the code posting frustration, I just started a thread in Forum Bugs and Suggestions with a possible solution. I know it's up to StudioPress to implement it, but more voices could help the cause.

    John


    John Sundberg | blackhillswebworks.com
    A WordPress developer’s toolbox: Firebug | WordPress Codex | Google 😉

    December 14, 2012 at 10:55 am #5225
    robskidmore
    Member

    Hey guys thanks for the responses.

     

    I probably should have made it clear what code I was trying to add to my template. This is what I am trying to do.

    add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );
    remove_action( 'genesis_after_post', 'genesis_do_author_box_single' );
    remove_action ( 'genesis_after_header', 'minimum_page_title');
    remove_action( 'genesis_after_header', 'genesis_do_nav' );
    remove_action( 'genesis_after_header', 'genesis_do_subnav' );
    remove_action( 'genesis_after_header', 'genesis_do_breadcrumbs' );
    remove_action( 'genesis_before_footer', 'genesis_footer_widget_areas' );
    remove_action( 'genesis_footer', 'minimum_custom_footer', 6 );
    remove_action( 'genesis_footer', 'genesis_footer_markup_open', 5 );
    remove_action( 'genesis_footer', 'genesis_do_footer' );
    remove_action( 'genesis_footer', 'genesis_footer_markup_close', 15 );

    I've tried variations of both of your suggestions.

    First

    I added this to the funtions.php still trying to use my writing.php template.

    /** Add the custom writing template */

    add_action( ‘genesis_after_header’, ‘minimum_writing_category’, 15 );

    function minimum_writing_category() {

    if (is_single() && in_category ( ‘writing’)) {

    require_once( get_stylesheet_directory() . ‘/writing.php’ ); }}

    Did not work. It removed all the changes that I had made with my original code.

    Second

    I tried adding the whole thing to my functions.php

    /** Add the custom writing template */

    add_action( ‘genesis_after_header’, ‘minimum_writing_category’, 15 );

    function minimum_writing_category() {

    if (is_single() && in_category ( ‘writing’)) {

    ...My code...  }}

    No luck.

    Third

    I removed the the first two attempts and added this to single.php (     in my child theme 🙂    )

    if (in_category ( ‘writing’)) {

    remove_action( 'genesis_post_content', 'genesis_do_post_content');
    add_action( 'genesis_post_content', 'writing_content_template');

    function writing_content_template () { ...My code... }}

    Still nothing

    Not sure where I'm going wrong. I got the best results from my original code it was just calling two templates and so I had duplicate content on the page.

     

    Appreciate your help guys.

    Any other suggestions.

    December 14, 2012 at 11:56 am #5235
    robskidmore
    Member

    Solved!!!!!!

     

    Like most things the answer was rather simple.

     

    I removed the writing.php and added this code to my single.php.


    if( is_singular() && in_category('writing')) {

    add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );
    remove_action( 'genesis_after_post', 'genesis_do_author_box_single' );
    remove_action ( 'genesis_after_header', 'minimum_page_title');
    remove_action( 'genesis_after_header', 'genesis_do_nav' );
    remove_action( 'genesis_after_header', 'genesis_do_subnav' );
    remove_action( 'genesis_after_header', 'genesis_do_breadcrumbs' );
    remove_action( 'genesis_before_footer', 'genesis_footer_widget_areas' );
    remove_action( 'genesis_footer', 'minimum_custom_footer', 6 );
    remove_action( 'genesis_footer', 'genesis_footer_markup_open', 5 );
    remove_action( 'genesis_footer', 'genesis_do_footer' );
    remove_action( 'genesis_footer', 'genesis_footer_markup_close', 15 );

    }

     

    Thanks friends. Couldn't have done it without you.

     

    🙂

    December 14, 2012 at 11:59 am #5236
    Jen Baumann
    Participant

    Glad you solved it.

  • Author
    Posts
Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Custom layout for posts in a category.’ is closed to new replies.

CTA

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

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 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