Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #514080

    Is there a way to add the Page Attributes box and the Templates selector to Posts?
    I have a site divided into several categories using custom templates and I’d love for the blogs that pertain to one category to use that template. I think this would be easiest using the selector to manually choose which template the post should use. But it also would work if the template could be triggered by the post category.

    Is this possible?

    #514488

    Hi Steeleroo!

    That wouldn’t be possible. You can create some custom post templates to use by creating new template files in the theme folder for them but I think it would be easier to just use the layout builder and then hit the big blue “Templates” button in the layout builder to save a layout that way.

    Best regards,
    Elliott

    #514730

    Thanks for the reply. I’m not referring to page content templates from the Page Builder. I am talking about the php templates.
    I already use several templates that I have customized and saved in my child theme folder which simply put different page tops using a different background and different menu for the different sections. I’d like to be able to assign posts to one of these template files. See http://shiningmountainwaldorf.org and the different sections from the top menu bar. I’d like to apply the Athletics page top to the posts that are in the Athletics category. I’ve made a copy of the category.php file from the wp-includes folder, but I’m not sure what to change in that code to all posts in the Athletics category use template-athletics.php which simply places the header-athletics.php on the page.
    I know this is a bit advanced, but I think it should only be a line of code.
    Thanks for any help.

    – Mark

    #514788

    Hey!

    What you can do is the an if statement, to the call of header

    Example:

    
    <?php if ( is_category('') ) { ?>
    <?php get_header('athletic'); ?>
    <?php } else { ?>
    <?php get_header(); ?>
    <?php } ?>

    and just make a header file with your changes and call it header-athletic.php

    Let me know if that helps

    Best regards,
    Basilis

    #516722

    Thanks again. That’s the approach I’d like, but I can’t get it working.
    I have tried adding this code to my template-builder.php file
    if ( is_category(‘athletics’) ) { get_header(‘athletics’);
    } else {
    get_header();
    }
    But it doesn’t work. I’ve tried several variations, both in my Enfold folder as well as my child theme folder.
    I do have a category called Athletics with slug athletics
    as well as the template-athletics.php file which works great for Pages that I have assigned the template to.

    Is there a different php file that calls the header before template-builder.php?
    I have also tried replacing the header call with the if-then statement on single.php, also with no luck.

    Thanks again for any advice.

    #517225

    Hi!

    Why did you get a copy of the category.php file from the wp-includes folder? It’s not a template file. Please refer to this link: https://developer.wordpress.org/themes/basics/template-hierarchy/#category

    Regards,
    Ismael

    #517399

    Hi Ismael,
    I originally thought that category.php might be the file I should copy to create a new category-athletics.php file with. But I haven’t changed it or done that. I’m simply asking where I need to save the code to call the Athletics header if the post has the category of Athletics. I already have a template-athletics.php file in my child theme folder which works great for the “Pages” since I can assign them in the page editor to use that template. But since there is no way to assign a template when editing “Posts,” I want to have a file that does that for me or add code to one of the files to say if the post is the athletics category then use my template-athletics.php file. I have tried making a copy of my template-athletics.php and naming it category-athletics.php and adding it to my child theme folder, but there was no difference. I also tried using the category number with category-116.php and this also did not work.

    I would like this post:
    http://shiningmountainwaldorf.org/shining-mountain-athletics-beautiful-new-gymnasium-floor-by-mike-hawkes-athletic-director/
    to have the same page top as these pages:
    http://shiningmountainwaldorf.org/athletics/
    which have a slightly different header background and a different main menu.

    From the Template Hierarchy page you referred to, I would expect all those posts with the athletics category to automatically use my template-athletics.php file without me having to add anything else, but it also does not.

    #517806

    Hi!

    Since you’re using the default post, you can modify the single.php file. Look for this code:

    get_header();
    

    .. add a conditional function. Something like this:

    if ( is_category('athletics') ) { 
    	get_header('athletics');
    } else {
    	get_header();
    }

    Regards,
    Ismael

    #518233

    Hi Again,
    that’s exactly what I tried first. And for some reason, it does not work. I’ve tried using the category ID as well. Also tried other categories to trigger a different header to see if it was something weird with athletics. But nothing seems to work.
    Could there be code in any of the other files that disregards this? single.php is essentially a template file, correct, for blog posts?

    If you have any idea why this doesn’t work, please let me know.
    Thanks!

    #519243

    Hey!

    I think this is more a general WordPress question than a theme related one and that’s why it would be best to ask this question inside of general WordPress forum. Try to activate a standard WordPress theme to see if you get the same result.

    Best regards,
    Andy

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