• Resolved jdestree

    (@jdestree)


    Hi again,

    I am looking for a way or plugin to display a flag on a post as new for a certain period of time. I have been searching the plugins and have not came across anything yet. Any ideas?

Viewing 15 replies - 1 through 15 (of 27 total)
  • Not too sure what ‘flag’ you want to use, but something like this in a post loop should work:

    <?php
    //display message if post is less than 46 days old
    $mylimit=46 * 86400; //days * seconds per day
    //$post_age = date('U') - get_post_time('U');
    $post_age = date('U') - mysql2date('U', $post->post_date_gmt);
    if ($post_age < $mylimit) {
    echo '&hearts; This post is still new &hearts';
    }
    ?>

    Thread Starter jdestree

    (@jdestree)

    Would there be a way to throw another variable into the mix and say…

    If there is a tag of “new” on a post, display the new icon for a certain period of time. If there is a tag of “updated” on a post, display that updated icon for a certain period of time and lastly, if there is a tag of “final” display that corresponding icon for a certain period of days?

    The reason I ask is that this blog will have some posts that short term.

    Thanks for your help!!!

    Thread Starter jdestree

    (@jdestree)

    Thoughts on the adding a ‘flag’ with tags??

    A bit ‘wordy’ but:

    <?php
    // get post tags, if post less than certain days and has specific tag, display message
    $tags = wp_get_post_tags($post->ID);
    $tagsarray = array();
    foreach ($tags as $tag) {
      $tagarray[] = $tag->name;
    }
    $taglist = implode(',', $tagarray);
    $newlimit = 90 * 86400; //days * seconds per day
    $newtag = 'new';
    $updatedlimit = 60 * 86400; //days * seconds per day
    $updatedtag = 'updated';
    $finallimit = 30 * 86400; //days * seconds per day
    $finaltag = 'final';
    $message = '';
    $post_age = date('U') - mysql2date('U', $post->post_date_gmt);
    if ( ($post_age < $newlimit) && (strpos($taglist, $newtag) !== false) ) {
      $message = '&hearts; This post is new &hearts;';
    }
    if ( ($post_age < $updatedlimit) && (strpos($taglist, $updatedtag) !== false) ) {
      $message = '&clubs; This post was updated &clubs;';
    }
    if ( ($post_age < $finallimit) && (strpos($taglist, $finaltag) !== false) ) {
      $message = '&diams; This post is final &diams;';
    }
    if ($message) {
      echo $message;
    }
    ?>
    Thread Starter jdestree

    (@jdestree)

    Thank you!

    If there is a tag of “new” on a post, display the new icon for a certain period of time. If there is a tag of “updated” on a post, display that updated icon for a certain period of time and lastly, if there is a tag of “final” display that corresponding icon for a certain period of days?

    Yes, MichaelH told you how to do this. Just echo an img tag instead of text and add some ifelse‘s to catch your other conditions.

    If you use tags you are going to have to manually updating them to make this work. That’s a lot of work. WordPress tracks the post date and the last updated. Follow MichaelH’s advice and use those to do the work for you.

    Thread Starter jdestree

    (@jdestree)

    wait, this only removes the image after the time right? Not the entire post?

    Thread Starter jdestree

    (@jdestree)

    @apljdi I wish I could do it with post date but because of the use of this blog install, I need the option to do it manually

    Thread Starter jdestree

    (@jdestree)

    hmmmm, I can’t seem to get this to work. All I have to do is add the code in the loop and add tags on my posts, correct?

    Thread Starter jdestree

    (@jdestree)

    I’m getting there.

    I managed to get it to work with two issues:

    1.) When the post has no tags, the previous message appears. i.e. First post was new, so the second post also shows new because it has no tags.

    2.) The messages appear two in each post.

    Yes well post your whole template at wordpress.pastebin.ca and report the link back here.

    Thread Starter jdestree

    (@jdestree)

    Go back and look at my code above — you changed around and messed up the message variable.

    Thread Starter jdestree

    (@jdestree)

    I went back to the code above and still get incorrect flags.

    Here is an image of my result: https://www.postimage.org/image.php?v=aV10djxr

    You will see I added an echo $tagsarray inside the if ($message) {
    echo $message;
    }

    Each post only has one tag associated with it: either new, final, updated or no tag at all

    You will see the tags seem to stack.

    Any ideas?

    Thread Starter jdestree

    (@jdestree)

    I am going crazy. I cannot figure this out! I’ve been working on this problem for many hours now.

Viewing 15 replies - 1 through 15 (of 27 total)
  • The topic ‘New status/flag/ribbon for posts’ is closed to new replies.