Community Forums › Forums › Archived Forums › Design Tips and Tricks › How do you create a generic template page for eleven40?
Tagged: custom template page, Eleven40
- This topic has 3 replies, 2 voices, and was last updated 11 years, 9 months ago by ramseyp.
-
AuthorPosts
-
April 6, 2013 at 8:18 am #33466Chris MooreMember
Hello,
I am trying to create a customized template page to use as a drop-down option in the Page Attributes section (after adding a page).
I got the page working with this much so far, but much is missing:
/*
Template Name: Thank You Page - Email
*/
get_header();
get_sidebar();
get_sidebar( $name = alt );
get_footer();I would like to fill in the gaps in the code so that I have a fully formed and structured page, just like a 3-column page in the eleven40 child theme (exactly like this page: http://demo.studiopress.com/eleven40/sample/sub-page-11/)
I would also like to have one last thing: I would like to have a loop that displays the last 5 posts of the blog in the middle of the content area of the page.
Thanks!
Resepctfully, Chris Moore
Web Dev, CSS Hacks, & Biz Consulting @ MooreCreativeIdeas.com / Blogging @ ReflectOnThis.comApril 6, 2013 at 8:58 am #33469ramseypMemberHi there,
First thing you need to do is redo the code you have in the template. Since you're using a Genesis child theme, the page template needs to become part of the Genesis environment. Redo you template to read like this:
<?php
/**
* Template Name: Thank You Page - Email
*
*/genesis();
That right there will make it a working page template and make it part of the genesis environment.
The second part you mention would involve replacing the standard post content functionality with a custom loop. With Genesis, you add or remove actions (functions) to manipulate the output. If you're not familiar with Nick's Genesis Framework overview, start here.
You would want this in your page template, before the genesis(); bit:
remove_action( 'genesis_loop','genesis_do_loop' );
This unhooks the default loop of that page so you can replace it with a custom one that grabs the 5 posts:
add_action( 'genesis_loop','my_custom_loop' );
Now we replace genesis_do_loop with our own function, my_custom_loop where the custom loop will go. We have to create this function before it can do anything.
function my_custom_loop() {
}
Between these brackets, { and }, we write what the function should do. You want the 5 latest Posts, so something like this would work:
function my_custom_content() {
$args = array(
'posts_per_page' => 5,
'post_status' => 'publish',
);
genesis_custom_loop( $args );
}The finished page template would look something like:
5,
'post_status' => 'publish',
);
genesis_custom_loop( $args );
}remove_action( 'genesis_loop','genesis_do_loop' );
add_action( 'genesis_loop','my_custom_loop' );genesis();
April 6, 2013 at 9:53 am #33482Chris MooreMemberI'm sorry, things didn't come out too clearly, I think because of the way code is handled in the forums here... Are you saying this:
remove_action( 'genesis_loop','genesis_do_loop' );
add_action( 'genesis_loop','my_custom_loop' );function my_custom_loop() {
function my_custom_content() {
$args = array(
'posts_per_page' => 5,
'post_status' => 'publish',
);
genesis_custom_loop( $args );
}
}
genesis();
Resepctfully, Chris Moore
Web Dev, CSS Hacks, & Biz Consulting @ MooreCreativeIdeas.com / Blogging @ ReflectOnThis.comApril 6, 2013 at 11:01 am #33498ramseypMemberApologies, the page template should contain ( besides the opening php tag and the comment block with the template name in it):
remove_action( 'genesis_loop','genesis_do_loop' );
add_action( 'genesis_loop','my_custom_loop' );
function my_custom_loop() {
$args = array(
'posts_per_page' => 5,
'post_status' => 'publish',
);
genesis_custom_loop( $args );
}
genesis();
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.