jquerywordpresssinglepage

Load Wordpress Page using jQuery to make Website 1 Page


I have created a wordpress website with min 6-7 pages of various content. I have make it behave like single page website using custom template with fix number of pages with below code.

$args = array(
      'post_type' => 'page',
      'orderby' => 'menu_order',
      'order' => 'asc',
      'post__in' => array(10,12,202,14,16,18,208,20) //list of page_ids
    );
    $page_query = new WP_Query( $args );
    //echo 'Post Id='.$post->ID;
    if( $page_query->have_posts() ) :
    echo '<div class="pages-on-page">';
    //print any general title or any header here//
    while( $page_query->have_posts() ) : $page_query->the_post();
    echo '<div class="page-on-page" id="page_id-' . $post->ID . '">';
    $content_post = get_post($post->ID);
    $content = $content_post->post_content;
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]&gt;', $content);
echo $content;
    //print any output you want per page//
    echo '</div>';
    endwhile;
    echo '</div>';

It is working fine untill i do not add new page to display. can anyone suggest me how to make it dynamic so that i dont have to give fix number of page id in array.


Solution

  • To list ID's of all pages, you can use wp_list_pluck as shown below

    $pages = get_pages(
        array (
            'parent'  => 0, // replaces 'depth' => 1,
            'exclude' => '3,5,11'
        )
    );
    
    $ids = wp_list_pluck( $pages, 'ID' );
    

    now

    'post__in' => $ids