How to differentiate a new post from a fixed post in wordpress?

Asked

Viewed 54 times

0

I need to know if a post is a new post or just a fixed post.

My code is this Aki:

<div class="row padding " >
   <div class="col-md-5 padding ">
        <?php the_post_thumbnail(); ?>
        <?php
            if ( is_sticky ()) echo '<div class="ribbon ribbon-top-left"> 
            <span>fixo</span></div>'    ?>
        <?php
        if ( is_page() !=1 ) If($cont == 0) echo '<div class="ribbon ribbon-top-left"> 
        <span>novo</span></div>'    ?>
    </div>
    <div class="col-md-7 padding ">
         <!-- Título do post -->
         <h2><?php the_title(); ?></h2>


        <!-- Autor -->
        <h5><?php the_author(); ?>,

        <!-- Data -->
        <?php  echo  get_the_date(); ?>

        <p>Última atualização: <?php the_modified_time(); ?></p>
        </h5>

        <!-- Resumo do post -->
        <?php the_excerpt(); ?>
    </div>
</div>

I’d like to put the div new written in the most recent post but the way I did if the person fixed a post to div ends up going to the wrong post, follows an image marking where it should be.

inserir a descrição da imagem aqui

  • 1

    I believe that Wordpress does not have a default Function for this, you should have to create one according to what you consider that a new post is new (less than 1 hour or less than 24 hours, etc.).

1 answer

0


Since I didn’t get an answer and couldn’t find a function, I decided to follow the tip from iamdlm

<?php $hora =  current_time ('timestamp') - get_the_time('U') ;
if ( $hora <= 259200 ) echo '<div class="ribbon ribbon-top-left"><span>novo</span></div>';    ?>

How does it work? Well the current_time ('timestamp') search the current time in Unix and the get_the_time('U') search for the time and date of when the post was published in Unix, Okay, so now what? Subtract the values and add to a variable after that is just do an If to see if the value is greater or less than the value in seconds you put that in my case is 72h and ready ta done

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.