¿Estás buscando una forma de mostrar un mensaje a tus usuarios para notificarles cuando un post tiene más de un año? Aunque probablemente exista un plugin para ello, hemos creado un rápido fragmento de código que puedes utilizar para notificar a los lectores de entradas antiguas en WordPress.
Instrucciones:
Todo lo que tienes que hacer es añadir este código al archivo single.php de tu tema.
<?php $time_defined_as_old = 60*60*24*365; // A Year if((date('U')-get_the_time('U')) > $time_defined_as_old) { echo '<div class="notice"><strong>Notice</strong><br />This article is published more than one year ago. Information in this article might be irrelevant with current situation</div>'; } ?>
Nota: Si es la primera vez que añades fragmentos de código en WordPress, consulta nuestra guía sobre cómo añadir correctamente fragmentos de código en WordPress, para no romper accidentalmente tu sitio.
Si te ha gustado este fragmento de código, por favor, considere revisar nuestros otros artículos en el sitio como: 43 temas de fotografía para WordPress y cómo crear un formulario de contacto en WordPress.
Is there a way to have it notify in admin instead of live if a post has reached a certain age?
How are you thinking to display this? like something within the posts columns.
Exactly, just an indicator next to the post that it hasn’t been updated in X number of months,days.
Also, it may be beneficial to have items in “Right Now” on the dashboard. older than 6 months, 1 year, etc.
Hi Zach I think you would need to have something on the dashboard, if the site was like wpsnipp.com I have over 460 posts as a result I would never see the icon unless I viewed very old posts. Ill look into the idea see if I can’t post a new snippet, great idea though.
The exact same thing would occur with us as well. That’s why I was saying adding it to “right now” might work.
[…] This post was mentioned on Twitter by HTMLfrp, WPSNIPP. WPSNIPP said: #wordpress Notify readers of old posts http://bit.ly/g5vVcB #blog please RT 🙂 […]
WordPress Notify readers of old posts – wpsnipp.com WordPress code snippets for your blog…
Adding this to your wordpress theme will display a message to your visitors to notify them when a post is over a year old….