• Hi, everyone. I am trying to set a different page as front page, depending on the value of a counter-variable. I created a child theme and placed the following code in it. Unfortunately it’s not working and I am not particularly firm with php. Any help in getting it to work is greatly appreciated.

    <?php
    // Exit if accessed directly
    if ( !defined(‘ABSPATH’)) exit;

    /* Add custom functions below */

    if (is_new_day() ):
    $SignupCounter = 0;

    if (is_page( ‘confirmed-signup’ ) ):
    $SignupCounter++;

    if ($SignupCounter == 0) : {
    $LP = get_page_by_path( ‘/home-0’ );
    update_option( ‘page_on_front’, $LP->ID );
    update_option( ‘show_on_front’, ‘page’ );
    }

    elseif ($SignupCounter == 1) : {
    $LP = get_page_by_path( ‘/home-1’ );
    update_option( ‘page_on_front’, $LP->ID );
    update_option( ‘show_on_front’, ‘page’ );
    }

    elseif ($SignupCounter == 2) : {
    $LP = get_page_by_path( ‘/home-2’ );
    update_option( ‘page_on_front’, $LP->ID );
    update_option( ‘show_on_front’, ‘page’ );
    }

    elseif ($SignupCounter == 3) : {
    $LP = get_page_by_path( ‘/home-3’ );
    update_option( ‘page_on_front’, $LP->ID );
    update_option( ‘show_on_front’, ‘page’ );
    }

    elseif ($SignupCounter == 4) : {
    $LP = get_page_by_path( ‘/home-4’ );
    update_option( ‘page_on_front’, $LP->ID );
    update_option( ‘show_on_front’, ‘page’ );
    }

    elseif ($SignupCounter >= 5) : {
    $LP = get_page_by_path( ‘/home-5’ );
    update_option( ‘page_on_front’, $LP->ID );
    update_option( ‘show_on_front’, ‘page’ );
    }

    ?>

Viewing 1 replies (of 1 total)
  • Thread Starter A. M. M.

    (@laius)

    Apparently I have to use

    elseif ($foo) ($SignupCounter==1) {

    instead of

    elseif ($SignupCounter == 1) : {

    But it is still not working. I tried something simpler too:

    $LP = get_page_by_title( ‘Fragen’ );
    update_option( ‘page_on_front’, $LP->ID );
    update_option( ‘show_on_front’, ‘page’ );

    And even this doesn’t work. There must be something wrong with the basics here. Can anyone help? Pleeeeaaasseee

Viewing 1 replies (of 1 total)
  • The topic ‘Set front page with php’ is closed to new replies.