• I’ve been dabbling with wordpress for the last few months and I must say I’ve always found it very easy to customize, and maintain…

    But today I ran into the first problem I couldn’t solve by reading the codex or searching these support forums… Here goes:

    I want to change the template for posts (single.php) older than a certain amount of weeks, days or months… Let’s say I want to display a certain text above all posts older than 25 days….

    Is that possible? I saw the date conditionals, but I couldn’t find a time difference conditional? Can this be achieved by a workaround?

    Thanks in advance!

Viewing 6 replies - 1 through 6 (of 6 total)
  • You may be able to rip some code from Ashwin Bihari’s old Auto-Delete- Posts plugin to get what you need. I have updated the plugin to work with WP 2.1.2 and you can get it here:
    https://digitalwestex.org/2007/03/23/auto-delete-posts-for-wordpress/

    Thread Starter jiiinx

    (@jiiinx)

    Thanks 2notch;

    I’ve been working with the plugin trying to get it to move but I’ve actually not moved an inch towards actually getting the single.php file to do something different for posts older than a certain days.

    I’m afraid I’m missing the obvious here ??

    Couldn’t you make a conditional statement around the post within the loop?

    If date is more than 25 days from today, do this. Otherwise, do this.

    Thread Starter jiiinx

    (@jiiinx)

    That’s the idea, yes. But how do I make this conditional statement, the statement can’t be found in the conditionals list ??

    Anyone?

    Try this:

    <?php
    	$today = date("r");
    	$articledate = get_the_time('r');
    	$difference = round((strtotime($today) - strtotime($articledate))/(24*60*60),0);
    
                if ($difference >= 25) {
                   Do Stuff Here
                }else{
                   Do Stuff Here
                }
    ?>

    That should 1) set today’s date, 2) set the post’s date, 3) find the difference, 4) Create a conditional based on the difference in days between today and the post date.

    The conditional and the initial variables need to be executed within the loop.

    Thread Starter jiiinx

    (@jiiinx)

    Blepoxp, thank you so much. This is working like a charm! Great! Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Conditional: for posts older than x weeks’ is closed to new replies.