WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Display different page on front page based on day of the week (3 posts)

  1. Galyn
    Member
    Posted 5 years ago #

    I have 5 Pages named Monday through Friday and I'd like the front page to display the content for that day's page. I figure it'll require a page template that compares the day of the week to the page number, which I can easily do, but I'm not 100% certain of how to pull the page content appropriately.

    I'm going to keep playing with it until I get it, but any help will be greatly appreciated!

  2. Christian Schenk
    Member
    Posted 5 years ago #

    Open the file index.php of your theme, search for the beginning of the loop, i.e. "if (have_posts()) : [...]". Right before this line add the following snippet:

    $dow2post = array(1 => 2, 2 => 3, 3 => 5, 4 => 7, 5 => 11, 6 => 13, 0 => 17);
    query_posts('page_id='.$dow2post[date('w')]);

    Adjust the values in the array so the corresponding keys (weekdays: 0 is Monday, 1 Tuesday, ..., 6 Saturday, 0 Sunday) point to the ID of the page you'd like to show.

    The page about query_posts may help you here.

  3. Galyn
    Member
    Posted 5 years ago #

    That worked beautifully, thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic