• Resolved timyoungorg

    (@timyoungorg)


    My website’s homepage (timyoung.ca), presents all Project Types together. What I’d like as the introductory page is to land on the design part of the menu and then have the visitor choose to click on the illustration category next or the info section etc. which I will soon add. Below is a solution to someone’s similar wish but with their blog. As someone in over my head in this case, I’ve made an attempt below this example to tweak it to suit the aim of a static page. Am I on the right track?

    <?php
    /**
    * Set custom post type archive as front page.
    *
    * @since 1.0.0
    */
    function ql_set_as_front_page( $query ) {
    if ( is_admin() || ! $query->is_main_query() ) {
    return;
    }
    if ( ql_is_front_page( $query ) ) {
    $query->set( ‘page_id’, ” );
    $query->is_page = false;
    $query->is_singular = false;
    $query->set( ‘post_type’, ‘MYCPT’ );
    $query->is_archive = true;
    $query->is_post_type_archive = true;
    }
    }
    add_action( ‘pre_get_posts’, ‘ql_set_as_front_page’ );

    /**
    * Taken from WP_Query::is_front_page and adapted to compare page_on_front with current page ID.
    *
    * @since 1.0.0
    *
    * @param object $query The main WP Query.
    */
    function ql_is_front_page( $query ) {
    if ( ‘posts’ == get_option( ‘show_on_front’) && $query->is_home() )
    return true;
    elseif ( ‘page’ == get_option( ‘show_on_front’) && get_option( ‘page_on_front’ ) && $query->get(‘page_id’) == get_option( ‘page_on_front’ ) )
    return true;
    else
    return false;
    }

    MY ALTERNATE ATTEMPT—

    <?php
    /**
    * Set custom project type archive as front page.
    *
    * @since 1.0.0
    */
    function ql_set_as_front_page( $query ) {
    if ( is_admin() || ! $query->is_main_query() ) {
    return;
    }
    if ( ql_is_front_page( $query ) ) {
    $query->set( ‘page_id’, ” );
    $query->is_page = false;
    $query->is_singular = false;
    $query->set( ‘project_type );
    $query->is_archive = true;
    $query->is_project_type_archive = true;
    }
    }
    add_action( ‘pre_get_design’, ‘ql_set_as_front_page’ );

    /**
    * Taken from WP_Query::is_front_page and adapted to compare page_on_front with current page ID.
    *
    * @since 1.0.0
    *
    * @param object $query The main WP Query.
    */
    function ql_is_front_page( $query ) {
    if ( ‘project_type’ == get_option( ‘show_on_front’) && $query->is_home() )
    return true;
    elseif ( ‘page’ == get_option( ‘show_on_front’) && get_option( ‘page_on_front’ ) && $query->get(‘page_id’) == get_option( ‘page_on_front’ ) )
    return true;
    else
    return false;
    }

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘homepage project type’ is closed to new replies.