WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Sidebar help (2 posts)

  1. armstrong1118
    Member
    Posted 6 years ago #

    Im would really like to add a mini loop to my sidebar that would show just the title of the post, and the date of the post.

    Ive tried a couple of things and neither of them have worked for me. I dont know if it has to do the code that already exists in my sidebar or what.

    Heres a link to the current code in my sidebar, can anybody help me out?

    http://wordpress.pastebin.ca/848164

  2. justinratwebtek
    Member
    Posted 6 years ago #

    Quick and dirty:

    <?php
    if(is_home()) {
    
    		echo "<li>
    		<span class='head'>LATEST NEWS</span>
    		</li>";
    	        echo "<ul>";
    
    		$lastposts = get_posts('numberposts=5');
    
    		foreach($lastposts as $post) :
    		setup_postdata($post);
        		?>
    			<li><a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a>
    		<?php
    		echo " <small>posted on: ";
    		echo the_time('F j, Y') . "</small></li><br />";
    		endforeach; 
    
    		echo "</ul>";
    } elseif (is_category(3) ||.....

    This'll help in the future if you continue to custom code.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.