Support » Themes and Templates » Display different page on front page based on day of the week

  • Resolved Galyn

    (@galyn)


    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!

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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.

    That worked beautifully, thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display different page on front page based on day of the week’ is closed to new replies.