• I am wanting to know if there is a way to display a different page for different days of the week. If there is not does anyone know any plugins that would help solve this?
    Thanks In Advance,
    Tim

Viewing 5 replies - 1 through 5 (of 5 total)
  • You mean the home page? Page with different content or different layout or.. ?
    If you want to change the content of your home page, you can create pages and every day change make them as the home pages in Settings → Reading. Just check Front page displays A static page and then select which one will be your Home page.

    Use something like this:

    $args = array(
        'posts_per_page' => 1,
    );
    
    $day_of_week = strtolower( date( 'l' ) );
    
    switch ( $day_of_week ) {
    
        case 'monday' :
            $args['cat'] = 1;
            break;
    
        case 'tuesday' :
            $args['cat'] = 2;
            break;
    
        case 'wednesday' :
            $args['cat'] = 3;
            break;
    
        case 'thursday' :
            $args['cat'] = 4;
            break;
    
        case 'friday' :
            $args['cat'] = 5;
            break;
    
        case 'saturday' :
            $args['cat'] = 6;
            break;
    
        case 'sunday' :
            $args['cat'] = 7;
            break;
    }
    
    $posts = new WP_Query( $args );
    
    if ( $posts->have_posts() ) {
    
        while ( $posts->have_posts() ) {
            $posts->the_post();
            printf( '<div class="entry-title"><a href="%s"><h2>%s</h2></a></div>', get_permalink(), get_the_title() );
            printf( '<div class="%s"><p>%s</p></div>', join( ' ', get_post_class() ), apply_filters( 'the_content', get_the_content() ) );
        }
    
    }
    
    wp_reset_postdata();

    I used category IDs to select different posts categories. You would have to replace the category IDs with your own category IDs.

    Thread Starter Tcrox

    (@tcrox)

    Charles, can you tell me where you are putting this code? Would this be in the index.php file?

    Thread Starter Tcrox

    (@tcrox)

    Media X,
    I do mean the home page, but I don’t want to have to go in manually and change it everyday. I want it to automatically change each day of the week.

    Charles, can you tell me where you are putting this code? Would this be in the index.php file?

    Try placing the code in that file and see what happens. You can always delete it if it doesn’t work.

    Which file the code goes in depends on your theme and on which page you want the post to show up on. The code is probably not complete and some other code may need to be deleted to make this code work.

    I assumed that you asking for a solution also meant you had enough experience and knowledge to edit themes. If not, you might want to start by reading the Theme Development article on the WordPress Codex. It has links to other pages, including the Template Hierarchy, used to determine which file you need to edit or to create.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Have Different Page Every Day’ is closed to new replies.