[resolved] Display most recent post and other content (3 posts)

  1. guitarcrazy087
    Posted 7 years ago #

    Okay so here's my problem. I have a side bar on the left in my header.php file. In this side bar I would like to display the title and date of my most recent post, no matter what is being displayed in the body of the site. i.e. a "page", a post from years ago, even the most recent post itself.

    I am new to editing the PHP of WordPress and all my attempts at this have failed. I have searched through the codex and found nothing that has worked so far.

    Any help is appreciated!



  2. Samuel B

    Posted 7 years ago #

  3. guitarcrazy087
    Posted 7 years ago #

    Okay, I found a way to do it. I did this:

    $my_query = new WP_Query('showposts=1');
    while ($my_query->have_posts()) : $my_query->the_post();
    	$do_not_duplicate = $post->ID;
    $title = "the_title()";
    echo $title;

    That's what I used for the first part. The other part still works.

    Thanks for the suggestion.

    I have one other question though: how do I capture the output of the_title() in a variable without it printing onto the page?


Topic Closed

This topic has been closed to new replies.

About this Topic