• Resolved acub

    (@acub)


    <?php
    /*
     * Template Name: Blog Posts
     * @package Customizr
     * @since Customizr 3.0.12
     */
    ?>
    
    <?php do_action( '__before_main_wrapper' ); ##hook of the header with get_header ?>
    <?php tc__f('rec' , __FILE__ , __FUNCTION__ ); ?>
    <div id="main-wrapper" class="container">
    
        <?php do_action( '__before_main_container' ); ##hook of the featured page (priority 10) and breadcrumb (priority 20)...and whatever you need! ?>
    
        <div class="container" role="main">
            <div class="row">
    
                <?php do_action( '__before_article_container'); ##hook of left sidebar?>
    
                    <?php query_posts('post_type=post&post_status=publish&posts_per_page=10&paged='. get_query_var('paged')); ?>
    
                    <div class="<?php echo tc__f( '__screen_layout' , tc__f ( '__ID' ) , 'class' ) ?> article-container">
    
                        <?php do_action ('__before_loop');##hooks the header of the list of post : archive, search... ?>
    
                            <?php if ( tc__f('__is_no_results') || is_404() ) : ##no search results or 404 cases ?>
                                <article <?php tc__f('__article_selectors') ?>>
                                    <?php do_action( '__loop' ); ?>
                                </article>
                            <?php endif; ?>
    
                            <?php if ( have_posts() && !is_404() ) : ?>
                                <?php while ( have_posts() ) : ##all other cases for single and lists: post, custom post type, page, archives, search, 404 ?>
                                    <?php the_post(); ?>
                                    <article <?php tc__f('__article_selectors') ?>>
                                        <?php
                                            do_action( '__loop' );
                                        ?>
                                    </article>
                                <?php endwhile; ?>
    
                            <?php endif; ##end if have posts ?>
    
                        <?php do_action ('__after_loop');##hook of the comments and the posts navigation with priorities 10 and 20 ?>
    
                    </div><!--.article-container -->
    
            	<?php wp_reset_query(); ?>
    
            	<?php do_action( '__after_article_container'); ##hook of left sidebar?>
    
            </div><!--.row -->
        </div><!-- .container role: main -->
    
        <?php do_action( '__after_main_container' ); ?>
    
    </div><!--#main-wrapper"-->
    
    <?php do_action( '__after_main_wrapper' );##hook of the footer with get_get_footer ?>

    Save the code above in your child theme folder, as blog.php, than select it as the page template for the page you want to display your blog on.

    You’re done. You can now have your blog on both front page and any other page at the same time.

    Besides, you can modify this template to display a different list of posts. Or anything else, really… like custom posts, posts from custom taxonomies, posts from a select number of categories, posts by one or more authors, posts with a specific value in a specific custom post meta, or any combination of the above. And more. Just see query_posts documentation. That’s where all the magic of this template resides.

    After you’ve made your query_posts() return the results you want, you need to change the name of the template accordingly, change the name of the file accordingly (there is a naming structure logic for templates in WP, if you want your template to apply automatically to different archives, for example) and select it as page template for the page you want to display the custom list on. Just don’t remove the

    &paged='. get_query_var('paged')

    part from query_posts(), or you will lose pagination.

    Enjoy.

Viewing 15 replies - 16 through 30 (of 35 total)
  • Hmm, thanks d4z_c0nf, but I can’t get this to work swapping out the the row that includes the hook for the sidebar. The article-container still displays with:
    <div class="span12 article-container" >
    regardless of which page layout I choose and crowds out the sidebar.

    Maybe full width is not so bad after all. LOL

    wanna copy the entire custom page template you’re using in pastebin.com and paste here the link?

    Sure, here you go. Apologies for the lack of coding skills.
    https://pastebin.com/XjU2kx26

    Thanks for the help.

    Oh I see, looks like the query_posts was place a bit too early, which, as you noticed, bothered tc__f( '__screen_layout' , tc__f ( '__ID' ) , 'class' )
    ??

    wanna try this?
    https://pastebin.com/MGAC1Tf5

    SWEET! Works like a charm!! Wish I new how to figure this stuff out myself, but I’m sure glad you were willing to help a newb. Thanks so much!

    Cheers!

    WordPress is well documented, and if you look into customizr code, step by step, you will learn a lot of things.
    For rapid snippets:
    https://www.themesandco.com/code-snippets/

    HI, this is fantastic! Thank you – just one query, in Customizr the right side bar is span3 & for some reason my side bar is now underneath this blog container rather than to the right. Is there some code I am missing?

    Sorted ??

    OK don’t have this sorted! Damn! Have changed

    ‘<div class=”row”>’
    ‘<div class=”<?php echo tc__f( ‘tc_column_content_wrapper_classes’ , ‘row column-content-wrapper’ ) ?>”>’

    then added in the get side bar:
    ‘ </div><!–.article-container –>

    <?php wp_reset_query(); ?>

    <?php do_action( ‘__after_article_container’); ##hook of left sidebar?>

    <?php get_sidebar( ‘right’ ); ?>

    </div><!–.row –>
    </div><!– .container role: main –>’

    Still have the right side bar under the blog list. The website link is: https://saegroup.com.au/about-us/sae-group-news/

    Thread Starter acub

    (@acub)

    What you need to do is change

    <div class="span12 article-container">

    into

    <div class="span9 article-container">

    Give me a pastebin of your current template and I’ll tell you where and what to change.

    Hey acub! The pastebin is https://pastebin.com/7aE6ZRP0 between you ElectricFeet & rdellconsulting I’ll be php ‘fundi’ in record time (well I’ll actually understand what I’m doing and be able to develop more great sites for small businesses. You have no idea how invaluable your help & sharing of your know-how is. THANKYOU!

    Thread Starter acub

    (@acub)

    Replace

    <div class="<?php echo tc__f( '__screen_layout' , tc__f ( '__ID' ) , 'class' ) ?> article-container">

    with

    <div class="span9 article-container">

    and you’re good to go.

    You’re welcome.

    But, the problem was solved in a slightly modified version of @acub template, I posted some comments above. That version leaves the filter where it should stay and is >= 3.1.9 compatible
    Heres a new link: https://pastebin.com/BaXPVxBj
    Any problem with that?

    You can achieve the same thing much more easily in another way, just putting the following into your child theme functions.php, without using templates, which in my opinion is a better choice. It will not suffer any changes to the core templates of customizr, unless nikeo decides to change the hook “__before_loop.” But in that case the maintenance is simple only having to change a string.

    add_action('__before_loop', 'my_blog_page', 5);
    function my_blog_page($query){
        if ( ! is_page('blog') ){ //assuming 'blog' is the page slug of the page you want to be your blog page
            return;
        }
        query_posts('post_type=post&paged='. get_query_var('paged'));
        add_action('__after_article_container', 'wp_reset_query', 5);
    }
    Thread Starter acub

    (@acub)

    The problem with your solution is that it also adds the featured pages block, duplicating the home page, while the template solution only produces a blog list. But basically, they use the same method: they both replace the main (page) query with a blog query, maintaining pagination.

    But, than again, why are we talking about problems? There is no problem. If you look closely, this was originally posted as a how-to, because a lot of people were asking how to achieve this. Replacing the query or its parameters can be done in numerous ways: raw sql, changing query params with pre_get_posts, replacing the query based on page slug or page id (your solution) or templating (my original solution).
    I opted for the template solution as I find it more WordPress-like: it gives the user the ability to switch from blog to normal page from the page back-end, not from functions.php. Please note that I am usually a big fan of functions.php mods and child themes.

    Cheers.

    Honestly I cannot see the problem with my solution you’re talking about, if you could give me a use case…
    “My” solution, if you’re talking about the second one, does the same thing of your solution but without using templates. Puts a query_posts as first action of the hook __before_loop (so almost where you put that), and puts a wp_reset_query as first action of the hook __after_article_container (where you put that), and does it for the page with the slug “blog”. I prefer that just ’cause is most independent from templates changes. In fact your template had to be updated after customizr 3.1.9 .
    It’s a choice, I’m not saying your solution isn’t good, in fact as you can see, at the beginning, I just modified your one putting the query posts after
    <div class="<?php echo tc__f( '__screen_layout' , tc__f ( '__ID' ) , 'class' ) ?> article-container">

    But maybe you was talking about me saying “But the problem was solved”.. I was referring to Leapmkt12 sidebar issue, which is the same experienced by zenny, and was solved in that pastebin I linked 3 weeks ago (doing what I described above).

    I agree with you about switching from blog to normal page from the page back-end is generally better. The only thing I’ve spotted, in fact, was about eventual (and already happened) maintaining issues with customizr upgrades, as I describe above.

    Cheers ??

Viewing 15 replies - 16 through 30 (of 35 total)
  • The topic ‘[Theme: Customizr] Add blog or custom post list templates to Customizr [How to]’ is closed to new replies.