Community Forums › Forums › Archived Forums › Design Tips and Tricks › Sample child theme custom blog page template?
- This topic has 13 replies, 3 voices, and was last updated 9 years, 7 months ago by pobrien.
-
AuthorPosts
-
August 10, 2014 at 12:05 pm #118082pobrienMember
Hi,
My site has a static front page, and a blog page. I'm trying to remove the default layout for the is_home() portion that's provided in the sample theme.
This is my best guess on doing that. Can anyone advise if there is another (more preferred) way of doing it? I've tried creating and manipulating a
page_blog.php
page, but haven't had much success.In my child theme's functions.php
function blogPageListSetup() { if (is_home()) { remove_action('genesis_loop','genesis_do_loop'); add_action('genesis_loop','blogPageList'); } } add_action('get_header', 'blogPageListSetup'); function blogPageList() { if ( have_posts() ) { while ( have_posts() ) { the_post(); // TEST CODE echo '<div class="title">'. the_title() .'</div>'; } } }
August 10, 2014 at 2:51 pm #118095AnitaKeymasterCan you share a link to your site please?
Love coffee, chocolate and my Bella!
August 10, 2014 at 3:01 pm #118099pobrienMemberNope, it's a private internal dev site. Basically my setup (for starters):
1) My blog is setup for static home page, and post page
2) I'm using the starter child theme for Genesis 2.1.2
3) I want to change the is_home to show only blog titlesHow do I go about doing that? Is there a hook? Do I need to have something special in the child theme's
page_blog.php
?August 10, 2014 at 3:35 pm #118104pobrienMemberOh, perhaps I found my answer. The template settings should be in a new file within the child theme called
home.php
Thoughts?
August 10, 2014 at 4:54 pm #118110pobrienMemberSo it feels a little "hackey" to me, but I took this Custom Loop example from Bill Erickson, and added it to
home.php
and was able to get the proper styling I needed for myis_home()
blog page template.https://gist.github.com/billerickson/3218052
I'm assuming this is a proper way of doing things, and not a hack?
August 10, 2014 at 6:08 pm #118111PorterParticipantTo my knowledge, that's the proper way to go about it. You create a template, assign it to your home page, and use a custom loop.
August 10, 2014 at 6:12 pm #118113pobrienMemberOkay, great. Based on many bits of info around Google, I made a new file,
home.php
. Defined it as a template by way ofTemplate Name: Blog
, then added the custom loop from Bill Erickson. Things are working as I'd expect. Thanks for confirming this is a proper way to do it (and not a hack).August 10, 2014 at 6:20 pm #118114PorterParticipantOne bit I missed, though I'm not 100% on how Genesis handles this.
There's actually no need to name it home.php. Naming a file home.php will overwrite any internal settings, and load that file instead, even over an index.php file. You could (and should, to my knowledge), be able to achieve the same thing by naming the file "template-home.php", and assinging the template manually within the WordPress dashboard. You can assign any page as your home page, so pick whatever "Home" page you come up with, assign it the proper template ("template-home.php"), and you should be good to go.
This will ensure you're not toying with the built in functionality of index.php / home.php as special file names, but achieve the same results.
Side note, I personally create a "templates" folder within my child theme, and store all template files in there, just for organization.
August 10, 2014 at 6:58 pm #118118pobrienMemberInteresting. This is why I thought it was a "hack", because when I name it something like
template-home.php
, and set the page template within the Dashboard to "Blog" or even "Custom Blog Page", then the child theme reverts back to default layout. It only works when I usehome.php
.Thoughts?
August 10, 2014 at 7:17 pm #118119AnitaKeymasterYou need it to be home.php. Or as front-page.php which is how the newer themes are being developed.
Love coffee, chocolate and my Bella!
August 10, 2014 at 7:24 pm #118122PorterParticipantCan you elaborate on why this is? Why is setting a template any different than creating a directly file for page? I'm not a WordPress expert, but I feel like this is going against a lot of what I know about the WordPress core.
If I was to create a custom child theme based off of the Genesis Sample Theme, would I not do it the way I described?
August 10, 2014 at 7:39 pm #118124pobrienMemberWould the same apply for a search results page? Making a
search.php
in the child theme?I'm not looking to override all of Genesis, but just customize the layout of the results (more than just CSS).
So,
home.php
andsearch.php
are needed? No custom loops for those results?August 10, 2014 at 7:59 pm #118127pobrienMemberAlso, what's interesting is that I don't need a
front-page.php
for my front page. Seems is_home() is the only picky one about needinghome.php
.August 11, 2014 at 2:22 pm #118278pobrienMemberI ended up using my
home.php
as the template file foris_home()
,is_archive()
andis_search()
using this snippet from Bill Erickson. It works great, and hopefully it's the right thing to do for future proofing this child theme.http://www.billerickson.net/code/use-single-template-for-home-archive-and-search/
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.