What is the best way to create a custom blog template ?

Community Forums Forums General Discussion What is the best way to create a custom blog template ?

This topic is: not resolved

This topic contains 9 replies, has 2 voices, and was last updated by  braddalton 1 year, 1 month ago.

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

    olivier.moreau
    Participant
    Post count: 48

    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 ?
    Thanks in advance

    http://omoro.fr
    #63045

    braddalton
    Participant
    Post count: 10355

    How about Genesis Simple Sidebars plugin?


    #63159

    olivier.moreau
    Participant
    Post count: 48

    Hi 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.

    #63409

    olivier.moreau
    Participant
    Post count: 48

    I 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=135

    You can use all kind of values. Check :

    http://codex.wordpress.org/User:JamesVL/query_posts

    #63562

    olivier.moreau
    Participant
    Post count: 48

    Well 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=135

    remove_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-actions

    It’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’ );

    #63583

    braddalton
    Participant
    Post count: 10355

    That’s good for a custom category archive. Glad you posted it. Thanks

    You can also use custom fields as well with this template.


    #63642

    olivier.moreau
    Participant
    Post count: 48

    Hi 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();
    
    #63644

    olivier.moreau
    Participant
    Post count: 48

    Actually 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/

    #63737

    olivier.moreau
    Participant
    Post count: 48

    Latest 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();
    
    #63747

    braddalton
    Participant
    Post count: 10355

    Probably need a bit more space around the thumbnail images


Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.