Forums

[resolved] Formatting "Today's Post" differently (5 posts)

  1. kylewriter
    Member
    Posted 9 months ago #

    Right now, on my site One Forty Fiction, I'm formatting my first post differently using the "in_category" tag, which has been working great for me for the past year. When I add a new post, I change the category of the last post, put the new post in the appropriate category for the formatting, save both, and I'm good to go. The last post goes to the regular formatting, the new post gets the special formatting, and everybody is happy.

    But now I have less time to dedicate to the site and I want to automate this process as much as possible. I want the special formatting to be based not on the category (which I have to change manually every day), but on the date of publication. Specifically, I want to make it so the post that gets published "today" contains the special formatting, and come midnight (or whatever), it gets changed to being formatted like all the others.

    Anybody have any idea how I might do this?

  2. alchymyth
    The Sweeper
    Posted 9 months ago #

    without detailed knowledge of your full code, this is a guess (if you have one loop only):

    instead of the
    if(in_category('whatever')) code,
    try
    if(!is_paged() && $wp_query->current_post == 0)

    this would target the top post on the front page.

    if this is not it, please paste the full code of your frontpage template into a http://pastebin.com/ and post the link to it here.

  3. kylewriter
    Member
    Posted 9 months ago #

    Thanks for the response. Here's the link to the full code:

    http://pastebin.com/gHbnPLHX

  4. alchymyth
    The Sweeper
    Posted 9 months ago #

    assuming that 'todays post' is always the latest post,
    try and change this line:

    <?php if ( in_category('3') ) { ?>

    to:

    <?php if(!is_paged() && $wp_query->current_post == 0) { ?>
  5. kylewriter
    Member
    Posted 9 months ago #

    That worked perfectly! Thanks so much. You've saved me about 45 minutes out of every weekday.

Reply

You must log in to post.

About this Topic

Tags