-
AuthorPosts
-
October 5, 2015 at 11:21 pm #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?
October 6, 2015 at 4:03 pm #514488Hi 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,
ElliottOctober 6, 2015 at 8:32 pm #514730Thanks 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
October 6, 2015 at 9:49 pm #514788Hey!
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,
BasilisOctober 10, 2015 at 2:12 am #516722Thanks 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.
October 12, 2015 at 10:15 am #517225Hi!
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,
IsmaelOctober 12, 2015 at 3:16 pm #517399Hi 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.
October 13, 2015 at 2:58 am #517806Hi!
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,
IsmaelOctober 13, 2015 at 5:39 pm #518233Hi 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!October 15, 2015 at 12:57 pm #519243Hey!
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 -
AuthorPosts
- You must be logged in to reply to this topic.