treehouse : what would you like to learn today?
Web Design Web Development iOS Development

WordPress Blog Loop in Footer

  • 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:
    <div class="fourcolumn">
    <h2>Latest Post</h2>
    <?php if ( ! have_posts() ) : ?>
    <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; ?>

    <?php 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; ?>
    </div>


    Functions:

    <?php function wpe_excerptlength_teaser($length) {
    return 8;
    }
    function wpe_excerptlength_index($length) {
    return 30;
    }
    function wpe_excerptmore($more) {
    return '...';
    } ?></blockquote>
  • You'll need to query the posts to make sure that only one shows up:
    <?php query_posts( 'posts_per_page=1' ); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <!-- post -->
    <?php endwhile; ?>
    <!-- post navigation -->
    <?php else: ?>
    <!-- no posts found -->
    <?php endif; ?>
  • This just creates errors when I put the first two lines in the place of the original. If I copy this in instead of my loop it does nothing.
  • Also, I just want posts from the blog feed. Does this only pull posts from the blog feed?
  • <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>
  • You're a genius! <3