• Hello all
    i want to display one post from a category for a specific time
    e.g. for 1 week or 1 month

    on search i found this useful code

    <?php
    // initialize new query of one post from category 11
    $my_query = new WP_Query('cat=11&showposts=1');
    
    // loop through the database to find related information
    while ($my_query->have_posts()) : $my_query->the_post();
    
    // set expiration time of two days
    $goAwayDate = time() - (60 * 60 * 24 * 2);
    
    // get date of sticky post
    $postDate = get_the_time('U');
    
    // if post is too old, do nothing
    if ($postDate < $goAwayDate) {
    
    // else show the post
    } else { ?>
    
    	<h1><?php the_title(); ?></h1>
    	<?php the_excerpt(); ?>
    
    <?php } endwhile; ?>

    ——————————-

    I want to select 2-3 posts from a certain category
    & then set show & expire time for each post i.e. 1 week or 1 month
    & then using if else statement show the post as per the time period
    & for else part (if all expired period expired) use the latest from that selected category 🙂

    thanx in advance

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter PuNK DeSi

    (@ades_ting)

    can someone help me on this 🙁

    on the 3rd line where it says:
    $my_query = new WP_Query(‘cat=11&showposts=1’);

    you can change this code to accomplish what you’re looking for,.,

    for example:

    $my_query = new WP_Query(‘cat=2,5,7&showposts=3’);

    Thread Starter PuNK DeSi

    (@ades_ting)

    @ johnibom : thanks

    i want to select 3 or 4 posts from a category
    & then set showing date of each selected post
    like this
    // set expiration time of two days
    $goAwayDate = time() – (60 * 60 * 24 * 2);

    so that each post get 1 week time & showed for 1 week only
    & next post for next week & so on
    using If else statement

    & in the absence (for else part)
    if date is out of defined limit pick the latest post from that category

    I can easily use If Else statement for query posts but dnt know how to implement with date/week function so to pick each post on weekly or basis…

    thanks if others can help

    Thread Starter PuNK DeSi

    (@ades_ting)

    any ?

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Display a post for a specific time !’ is closed to new replies.