• Resolved kylewriter

    (@kylewriter)


    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?

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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 https://pastebin.com/ and post the link to it here.

    Thread Starter kylewriter

    (@kylewriter)

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

    https://pastebin.com/gHbnPLHX

    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) { ?>

    Thread Starter kylewriter

    (@kylewriter)

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

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Formatting "Today's Post" differently’ is closed to new replies.