• Hi,

    I’m using the following code to get the most recent blog entry:

    <?php query_posts('showposts=1'); ?><?php the_title('<span style="font-weight:bold">', '</span>'); ?><br /><?php while (have_posts()) : the_post(); ?><?php the_content_rss('', TRUE, '', 14); ?><?php endwhile;?>

    However, I wonder how I could get the first 3 letters of the month and the day number. For example 21st June would be JUN 21.

    Can someone help?

    Also, is there a way to restrict what ‘category’ it’s retrieved from?

    I’ve looked in the codex, but with no success.

    Thank you!

Viewing 14 replies - 1 through 14 (of 14 total)
  • You can restrict the category you want to show by changing the parameters inside query_posts(). Like: query_posts('showposts=1&cat=1');, that would show the latest article in the category with ID 1. More info here:
    https://codex.www.ads-software.com/Template_Tags/query_posts#Exclude_Categories_From_Your_Home_Page

    As for showing the date:

    <?php the_time('M j'); ?>

    Thread Starter michaelmcguk

    (@michaelmcguk)

    Many thanks, what a speedy reply ??

    Only problem, now is with the title:

    <?php query_posts('showposts=1&cat=5'); ?><?php the_title('<span style="font-weight:bold">', '</span>'); ?><br /><?php while (have_posts()) : the_post(); ?><?php the_content_rss('', TRUE, '', 14); ?><?php endwhile;?> it doesn’t show the correct title relating to the most recent post in that category ??
    Any ideas?

    Do you have your own site? Would love to see what you can do with WP ??

    Check out https://wpguy.com/ for all your wp_guy needs.

    (wp_girls apply within!)

    Thread Starter michaelmcguk

    (@michaelmcguk)

    Only problem, now is with the title:

    <?php query_posts('showposts=1&cat=5'); ?><?php the_title('<span style="font-weight:bold">', '</span>'); ?><br /><?php while (have_posts()) : the_post(); ?><?php the_content_rss('', TRUE, '', 14); ?><?php endwhile;?>

    it doesn’t show the correct title relating to the most recent post in that category ??

    Any ideas?

    it will really help you a lot in future, if you spend some time trying to understand the code you’ve got there…

    lets go through it shall we?, perhaps in the right order…

    <?php query_posts('showposts=1&cat=5'); ?>

    sets up your post query… actually pulls data from the database, but does nothing to display it.

    <?php while (have_posts()) : the_post(); ?>

    While there are posts left to display, lets do some stuff for each of them…

    <?php the_title('<span style="font-weight:bold">', '</span>'); ?>

    Here’s the title, we should probably display that for each post INSIDE this while-loop we have going here.

    <?php the_content_rss('', TRUE, '', 14); ?>

    after the title, and still for each post within the while-loop, lets display the content!

    <?php endwhile;?>

    Lets keep doing this, but only while there are still posts to display, right? All good things must come to an end ??

    does that help a bit? – learning to read code is much easier than writing it, and it will help you heaps when editing your themes in future.

    You need to put the_title() inside the loop…

    <?php query_posts('showposts=1&cat=5'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php the_title('<span style="font-weight:bold">', '</span>'); ?>
    <br />
    <?php the_content_rss('', TRUE, '', 14); ?>
    <?php endwhile;?>

    Aw… You da man Ivovic ??

    lol get out of my time zone ??

    (I mean forgive me for stepping on your toes, lol)

    Thread Starter michaelmcguk

    (@michaelmcguk)

    Uhm, I’m even more lost now heh.

    Aaaah get you now.

    I’m more of a C# man at heart, just started this WP way of things so bear with me ??

    Michael, you can cut and paste what wp_guy posted, and you’ll be just fine.

    the point though is, this while-loop, which begins with “while” and ends with “endwhile” is where the repeating action happens.

    So, if you have more than one post, and you want to do something for each of those posts, you’ll need to put that stuff between the “while” part and the “endwhile” part.

    Its similar to plain english.

    Say to yourself, “While I’ve got rotten fruit, I’ll throw it at Ivovic, then I’ll stop.”

    The idea being that you don’t just have one piece of fruit – you have a whole basket full of it right? so you don’t throw once, you throw repeatedly.

    (and I dodge)

    @ivovic: Stupid question but how come your name is linked to your website and mine isn’t?

    Thread Starter michaelmcguk

    (@michaelmcguk)

    Hah yes, completely understand what a WHILE loop is, no worries there ?? I just got a bit lost at one point ??

    I would never throw fruit at my favourite action hero! ??

    then you’ll have to forgive me for stealing your lunch.

    @wp_guy – I think it has something to do with your joining date, or your post count or something — mine wasn’t like that in the beginning, but as I’ve been around long enough not to be deemed a spammer, my site appears linked.

    I’m sure yours will too, in time.

    Sweet! ??

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Get Month and Day from the_excerpt?’ is closed to new replies.