mindtheGaspar
mindtheGaspar

Reputation: 463

Add a second Wordpress Loop that displays latest posts in single.php

I am creating my own Theme, but have only basic knowledge of PHP. I've been looking for a way to do this online but cannot seem to come across it.

This is the url of my development server: http://dev.mindthegaspar.com/nuevanacion/

I want to have a secondary loop in every page on the sidebar that displays all the latests posts. It is straightforward on the main Index.php file.

I'm not sure where yo begin to get it working on the Single.php file. I understand he concept of the WordPress loop, and why it won't work inside a Category of Post page, but is there a way around this?

Thanks

Upvotes: 1

Views: 429

Answers (1)

David
David

Reputation: 5937

add this to your sidebar:

$today = getdate();
$sidebarquery = new WP_Query( 'year=' . $today["year"] . '&monthnum=' . $today["mon"] . '&day=' . $today["mday"] );

while($sidebarquery->have_posts()) {
   $sidebarquery->the_post();
   echo '<li>' .  the_permalink(); . '</li>';
}

Upvotes: 1

Related Questions