WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] HOWTO: Show a post for only 5 days (6 posts)

  1. shaunandrews
    Member
    Posted 8 years ago #

    My index page has two loops. The first loop only shows one post from one category, sort of a sticky post implementation. My question is how can I have this post show for only a certain amout of time, say 5 days.

    Here's my query:

    WP_Query('category_name=news&showposts=1')

    So basically I want to use some logic to only show the post if its date falls within the last 5 days.

  2. shaunandrews
    Member
    Posted 8 years ago #

    no one?

  3. shakeb
    Member
    Posted 8 years ago #

    OK,
    I am relatively new to WordPress but If I were you I would think that cronjob/crontab is one way to do this.
    There is a crontab plugin http://www.skippy.net/blog/category/wordpress/plugins/wp-cron/
    Also here is a link to timestamp plugin
    http://wp-plugins.net/plugin/set-postdate/

    get the timestamp check it using crontab and if it matches your criteria delete/hide that post. (There could be a plugin for hiding posts )
    If you know PHP you would probably know what I am getting at.

    I haven't checked WP APIs yet and have no idea how it is coded. A developer could probably hint and suggest what to do.

    P.S. I could be totally wrong though :(

    Regards
    Shakeb

  4. shaunandrews
    Member
    Posted 8 years ago #

    I got it all figured out. I ended up using some PHP to compare the current date to the date of the post using Unix time. Worked like a charm.

    I'll be posting an in-depth tutorial shortly at http://www.shaunandrews.com/

  5. yosemite
    Member
    Posted 8 years ago #

    Cool, and kudos for thinking of others (tutorial)!

  6. shaunandrews
    Member
    Posted 8 years ago #

    As promised here's a tutorial on how to do sticky posts that dissapear after a few days:

    WordPress Sticky Posts

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags