• 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 5 replies - 31 through 35 (of 35 total)
  • You are a legend! Worked beautifully. To be honest I quite like the FP effect on the images in the blog list. Like most of the others here I look forward to the day I can look at this code & actually understand exactly what is happening. Really appreciate the support & this ongoing conversation has actually explained some of the php ?? Thanks again!

    Thread Starter acub

    (@acub)

    d4z_c0nf solution is more flexible and indeed won’t break so easily on parent theme updates, unless the hook we use to switch the query is dumped from the theme (and that’s not likely to happen).

    As for understanding the code, the principle here is quite simple: we replace the main loop (in our case a single page loop) with a post loop (if we feed more query args to the query_post we can make it more specific (include/exclude cats, maybe query some custom post type instead of posts, etc…)).

    The wp_reset_query() switches back to the original page loop.

    If we make the switch soon, let’s say on init (when WP starts rendering the page), index.php will know we’re on a post list page and will render both slider and featured pages block.

    If we make the switch on __before_article_container we won’t have slider but we’ll have the featured posts loop.

    And if we do it on __before_loop we’ll only have the post list, without slider or featured posts block.

    Note: the solution using hooks to change the query should be done from functions.php, using the default template for the page and the function changing the query should have a conditional based on page id or slug.

    HI guys, have just updated to Featured Pages Unlimited & now the blog has disappeared?? https://saegroup.com.au/about-us/sae-group-news/
    Help!! I’ve gone through all the codes & I can’t seem to get it right. It was working beautifully!

    Don’t think fpu upgrade caused the issue. I can see this in that page:

    <div id="content" class="span9 article-container">
    
    <article >
    </article>
    <article >
    </article>
    <article >
    </article>
    <article >
    </article>
    <article >
    </article>
    <article >
    </article>
    <article >
    </article>
    <article >
    </article>
    <article >
    </article>
    <article >
    </article>
    
    </div><!--.article-container -->

    So the loop goes through ten articles but for some reason contents/titles/article selectors are not printed.. if you haven’t changed anything to customizr core .. could be a plug-in issue (but not fpu, as far as I now..)

    If you require assistance then, as per the Forum Welcome, please post your own topic instead of tagging onto someone else’s topic.

    I am now closing this 8 month old resolved topic as it references an older version of WordPress.

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