Community Forums › Forums › Archived Forums › General Discussion › What is the best way to create a custom blog template ?
Tagged: custom blog template
- This topic has 9 replies, 2 voices, and was last updated 10 years, 7 months ago by Brad Dalton.
-
AuthorPosts
-
September 17, 2013 at 1:17 pm #63028olivier.moreauMember
Hello everybody,
My site : omoro.fr (WPMU)
Page involved : omoro.fr/expositions/
Theme : Studiopress Agency (modified)I'm trying to create a page to display all posts belonging to one category (let's say ID=135).
The simplest way is, of course, to create a link in the menu to show that category : http://omoro.fr/category/expositions/
But I have no control of that pseudo page and I'd like to have different sidebar than the blog.Then I've tried with plugins ( like "List category posts" ) but I'm not at all happy with the presentation.
Then I created a custom template with PHP code following WP Codex and other examples. It's much better but I have side issues with sidebars and such. It's not clean at all. That's what is running now at omoro.fr/expositions/
From what I understand, the page_blog.php should be used as a model but it's very empty and "The blog page loop logic is located in lib/structure/loops.php". In loops.php, we find : $include = genesis_get_option( 'blog_cat' );
Well that 'blog_cat' variable seems to be set in the theme setting and should be the simplest way to control what I want in my custom blog. I tried (very naively probably) to just set that variable in my custom template before calling Genesis loop.//* Template Name: Blog-expo $blog_cat = 135; genesis();
It doesn't work at all but somehow I feel this should be best approach...
Anybody can suggest an elegant solution ?
http://omoro.fr
Thanks in advanceSeptember 17, 2013 at 3:11 pm #63045Brad DaltonParticipantSeptember 18, 2013 at 6:03 am #63159olivier.moreauMemberHi Brad,
Thanks for your reply, I'm sure you have the solution !It is precisely because I want to use Genesis Simple Sidebars (GSS) that I have this problem... You see, I started with a standard page about the expos and I used GSS to have a specific sidebar. That was fine but it is a pain to do that page manually. It is much more efficient to just select posts with the category "expos" (ID = 135) and get that page filled up automatically. I started with a menu link to the selected posts but that doesn't create a real page where I can use GSS. Then I used a plugin, but it's not easy to respect my graphic chart with that solution.
So I decided to create a custom made template (thanks again to show me that technique in a previous question that you answered). I got that custom template working fine but when I put in the GSS sidebar the page looks weird (as you can see at http://omoro.fr/expositions/). Thus I figured out that I should start from the standard blog template of Genesis (page_blog.php) and simply change the input. I think the control variable is 'blog_cat' but how can I do that ?
To summarize : How can we create a custom blog template where the only change is the selection of posts ? Once this template is OK, it's easy to add GSS and all kind of other stuff in the pages using it.
Thanks in advance for your smart advices.
September 19, 2013 at 12:25 pm #63409olivier.moreauMemberI found the EASY way without ANY coding at all !
http://www.basicwp.com/filter-posts-by-category-tag-genesis/#
You simply create a page with the blog template and you add a custom field
name : query_args
value : cat=135You can use all kind of values. Check :
September 20, 2013 at 1:10 pm #63562olivier.moreauMemberWell I'm a bit stud born so I also find the way to create a custom blog template where the only change is the selection of posts. This is the code :`
<?php
//* Template Name: Blog-custom
//* Display only posts with Category ID=135remove_action('genesis_loop', 'genesis_do_loop');
add_action('genesis_loop', 'customblog_do_loop');
function customblog_do_loop() {
$args = array ( 'cat' => 135, 'order' => 'ASC' );
genesis_custom_loop( $args );
}
genesis();
`I found it after reading this excellent tutorial
http://designsbynickthegeek.com/tutorials/genesis-explained-framework-actionsIt's much easier with custom field in the standard blog template but the code is more flexible.
For instance you can add :remove_action( 'genesis_after_post_content', 'genesis_post_meta' );
September 20, 2013 at 3:53 pm #63583Brad DaltonParticipantThat's good for a custom category archive. Glad you posted it. Thanks
You can also use custom fields as well with this template.
September 21, 2013 at 6:41 am #63642olivier.moreauMemberHi Brad,
You read my mind ! I was working on getting a custom field from my custom blog template to select the category (so I don't have to create a template doing only cat=135).To start simpler I was trying to replace the post metadata with a custom message stored in a field. But I just cannot get the field 'customblog_message' as a proper input for my second function. I tried with genesis_get_custom_field() but it's not OK. Any idea what's wrong ?
<?php //* Template Name: Blog-custom //* Display only posts with Category ID=135 remove_action('genesis_loop', 'genesis_do_loop'); add_action('genesis_loop', 'customblog_do_loop'); function customblog_do_loop() { $args = array ( 'cat' => 135, 'orderby' => 'date' ); genesis_custom_loop( $args ); } remove_action( 'genesis_after_post_content', 'genesis_post_meta' ); add_action( 'genesis_after_post_content', 'customblog_after_post' ); function customblog_after_post() { global $customblog_message; ?> <p class="customblog_post-meta" ><?php echo 'TEST'; echo genesis_get_custom_field('customblog_message'); } genesis();
September 21, 2013 at 7:08 am #63644olivier.moreauMemberActually the above code is working fine but the customblog_message must be in the post and not in the page made with the customblog template. That wasn't what I planned but it can also be useful...
You can check the result at http://omoro.fr/zdoc/test-blog-custom/September 22, 2013 at 7:12 am #63737olivier.moreauMemberLatest version of the custom blog template...
Compare http://omoro.fr/zdoc/test-blog-custom/
with the standard layout : http://omoro.fr/category/expositions/<?php //* Template Name: Blog-custom //* Display only posts with Category ID=135 remove_action('genesis_loop', 'genesis_do_loop'); add_action('genesis_loop', 'customblog_do_loop'); function customblog_do_loop() { $args = array ( 'cat' => 135, 'orderby' => 'date' ); genesis_custom_loop( $args ); } remove_action( 'genesis_before_post_content', 'genesis_post_meta' ); remove_action( 'genesis_after_post_content', 'genesis_post_meta' ); add_action( 'genesis_before_post_content', 'customblog_meta' ); function customblog_meta() { global $customblog_message; ?> <p class="customblog_post-meta" ><?php echo genesis_get_custom_field('customblog_message'); } remove_action( 'genesis_post_content', 'genesis_do_post_content' ); add_action( 'genesis_post_content', 'customblog_content' ); function customblog_content() { $img = genesis_get_image( array( 'format' => 'html', 'size' => genesis_get_option( 'image_size' ), 'context' => 'archive', 'attr' => genesis_parse_attr( 'entry-image' ), )); printf( '<a href="%s" title="%s">%s</a>', get_permalink(), the_title_attribute( 'echo=0' ), $img ); } genesis();
September 22, 2013 at 10:13 am #63747Brad DaltonParticipant -
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.