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]
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 :/.
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.
chibiwawa@gmail.com
Member
Posted 7 months ago #
Sorry, what else can you select?
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 :/.
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".
chibiwawa@gmail.com
Member
Posted 7 months ago #
The post from the blog, or index page. Can you not pull posts from a page?
chibiwawa@gmail.com
Member
Posted 7 months ago #
Never mind I see that there is "pagename".
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
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.
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.
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?
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.
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.
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; ?>
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!