Forums

How to put Blog Loop on Every Page (19 posts)

  1. chibiwawa@gmail.com
    Member
    Posted 7 months ago #

    I'm trying to figure out how to have a latest post blog loop on every page in my footer. This is my theme: http://lwebdesigns.net/blog/. How do you make a loop for the blog content on every page?

    This is the code I am using:

    Footer:

    [Code moderated as per the Forum Rules. Please use the pastebin]

  2. esmi
    Theme Diva & Forum Moderator
    Posted 7 months ago #

  3. chibiwawa@gmail.com
    Member
    Posted 7 months ago #

    Thanks, I have read through multiple_loops before. I know it talks about calling the categories. How do you call the blog feed from the index? This seems like it should be something simple :/.

  4. esmi
    Theme Diva & Forum Moderator
    Posted 7 months ago #

    I know it talks about calling the categories.

    No it doesn't. It just includes code examples that select posts from a specific category. You have to decide what selection criteria to use in your secondary query.

  5. chibiwawa@gmail.com
    Member
    Posted 7 months ago #

    Sorry, what else can you select?

  6. esmi
    Theme Diva & Forum Moderator
    Posted 7 months ago #

  7. chibiwawa@gmail.com
    Member
    Posted 7 months ago #

    So to call the blog feed I would put this in functions:

    <?php
    
    // The Query
    $query = new WP_Query( 'name=blog' );
    
    // The Loop
    while ( $the_query->have_posts() ) : $the_query->the_post();
    	echo '<li>';
    	the_title();
    	echo '</li>';
    endwhile;
    
    // Reset Post Data
    wp_reset_postdata();
    
    ?>

    I guess there is no way to use index.html. Also, how do I call this in the feed? I will keep reading. Sorry, I'm a little slow :/.

  8. esmi
    Theme Diva & Forum Moderator
    Posted 7 months ago #

    I would put this in functions

    No. First you have to decide what posts you want to pull in this secondary query. What you have posted above would only pull in a single post with the slug "blog".

  9. chibiwawa@gmail.com
    Member
    Posted 7 months ago #

    The post from the blog, or index page. Can you not pull posts from a page?

  10. chibiwawa@gmail.com
    Member
    Posted 7 months ago #

    Never mind I see that there is "pagename".

  11. chibiwawa@gmail.com
    Member
    Posted 7 months ago #

    <?php if ( ! have_posts() ) : ?>
    <?php
    // The Query
    $query = new WP_Query( 'pagename=blog' );
    // The Loop
    while ( $the_query->have_posts() ) : $the_query->the_post();
    	echo '<li>';
    	the_title();
    	echo '</li>';
    endwhile;
    // Reset Post Data
    wp_reset_postdata();
    ?>

    I'm guessing this is completely wrong

  12. esmi
    Theme Diva & Forum Moderator
    Posted 7 months ago #

    Can you not pull posts from a page

    Assuming you're referring to your main post page - no. Because that page lists every post you've ever published. Queries don't work based on what archive page posts are displayed in. They work by selecting posts based on criteria that are specific to the posts themselves - category, tag, status etc.

  13. chibiwawa@gmail.com
    Member
    Posted 7 months ago #

    Haha, okay. That is what I have been saying all along. So you cannot pull all of your posts on any other page but the home because the is no way to target them. Nice.

  14. esmi
    Theme Diva & Forum Moderator
    Posted 7 months ago #

    No! That's not true! If you want all posts, then use post_status => publish. But are you really going to want to to show every post ever published in your site's footer?

  15. chibiwawa@gmail.com
    Member
    Posted 7 months ago #

    No, I want to show the 5 most recent out of all of the posts. I know you can display the most recent post titles with a widget. However, I want a description under each one.

  16. chibiwawa@gmail.com
    Member
    Posted 7 months ago #

    I've never heard of post_status => publish. I'm not very good at php. So obviously this is over my head.

  17. esmi
    Theme Diva & Forum Moderator
    Posted 7 months ago #

    So use $query = new WP_Query( 'posts_per_page=5' );
    http://codex.wordpress.org/Function_Reference/WP_Query#Pagination_Parameters

  18. chibiwawa@gmail.com
    Member
    Posted 7 months ago #

    I tried this and it just brings back errors:

    <?php if (have_posts()) : ?>
    <?php
    // The Query
    $query = new WP_Query( 'posts_per_page=5' );
    
    // The Loop
    while ( $the_query->have_posts() ) : $the_query->the_post();
    	echo '<li>';
    	the_title();
    	echo '</li>';
    endwhile;
    
    // Reset Post Data
    wp_reset_postdata();
    ?>
         <?php endif; ?>
  19. chibiwawa@gmail.com
    Member
    Posted 7 months ago #

    I posted this on CSS-Tricks.com and someone said to use this:

    <div class="fourcolumn">
            <h2>Latest Post</h2>
    
            <?php query_posts( 'posts_per_page=1' ); ?>
            <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
                    <div class="lp-dates"><?php the_time('M <br /> j') ?></div>
    
                    <div class="latest-post"><a href="<?php the_permalink(); ?>"><?php wpe_excerpt('wpe_excerptlength_teaser', 'wpe_excerptmore'); ?></a><div class="dash-divider"></div></div>
            <?php endwhile; ?>
    
            <?php else: ?>
                    <h1>Not Found</h1>  
    
                    <p>Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post</p>
            <?php endif; ?>
    </div>

    It works perfect!

Reply

You must log in to post.

About this Topic