WordPress.org

Forums

display multiple pages on one page (12 posts)

  1. martinbelton
    Member
    Posted 1 year ago #

    I would really like to display multiple pages on one page. I have looked at a number of similar questions and examples, but as a complete beginner in WordPress, I am struggling a bit. I would like to be able to do it on the pages themselves by using inline php (I am using Insert PHP plugin), and would really like some advice on this.

  2. alchymyth
    Forum Moderator
    Posted 1 year ago #

    you can code a loop either based on get_pages() or on `WP_Query()';

    https://codex.wordpress.org/Function_Reference/get_pages

    https://codex.wordpress.org/The_Loop
    http://codex.wordpress.org/Class_Reference/WP_Query

    what theme are you using?

  3. martinbelton
    Member
    Posted 1 year ago #

    twenttwelve

  4. martinbelton
    Member
    Posted 1 year ago #

    I don't suppose it would be possible to give me an example? As a newcomer, I am finding it a little difficult following the codex pages at the moment. I presume I have to revert to the default permalinks to find the page_id first?

  5. alchymyth
    Forum Moderator
    Posted 1 year ago #

    display multiple pages on one page

    basic example using WP_Query():

    <?php
    $args = array(
      'post_type' => 'page',
      'post__in' => array( 2, 5, 35, 67 ) //list of page_ids
    );
    $page_query = new WP_Query( $args );
    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 . '">';
    //print any output you want per page//
    echo '</div>';
    endwhile;
    echo '</div>';
    else:
    //optional text here is no pages found//
    endif;
    wp_reset_postdata();
    ?>

    (not tested)

  6. martinbelton
    Member
    Posted 1 year ago #

    Thank you very much for this - I can't seem to implement it though. I have pasted this into a page, changing list of page_ids to fit, using [insert_php]...[/insert_php] instead of <?php ... ?> using this plugin. Should I be adding it into a php file instead? (The pages.php file in them folder?) If so, should I be replacing some part of the original code with this, or just adding it in?

  7. WP Sites - Brad Dalton
    Member
    Posted 1 year ago #

    Martin, forget the plugin.

    You haven't stated exactly what content you want to display.

    Just the page titles, excerpts or full content of each page?

    For Linked Page Titles Only:

    You can also use wp_list_pages if you only want the title

    <?php wp_list_pages('include=7,13,26,35&title_li=' ); ?>

    Displays a list of WordPress Pages as links

    You can use the tag directly in any template file or in a custom function with hook and conditional tag.

    Otherwise, use the new WP_Query code above by alchymyth however you will need to add tags for the excerpt, content or get_template_part here (//print any output you want per page//) as it doesn't include them and will display nothing as is.

  8. martinbelton
    Member
    Posted 1 year ago #

    @ Brad Dalton - thank you! finally managed it - thank you so much for your help - breakthrough at last!!

  9. martinbelton
    Member
    Posted 1 year ago #

    What command do I need to include the content?

  10. WP Sites - Brad Dalton
    Member
    Posted 1 year ago #

    You can use the content template tag which you can grab from one of the files. Or you could use the_excerpt.

    You still haven't answered the question

    You haven't stated exactly what content you want to display.

  11. bfdeveloper
    Member
    Posted 9 months ago #

    Hi ,

    If you want to include the content of the pages then how should you go about it .

  12. zemirah
    Member
    Posted 6 months ago #

    Hi guys, I'm having similar issue. I would like to be able to add multiple pages to a page. Kind of like this site here- http://vickyflipfloptravels.com/category/weekender/
    I dont know how to go about it and would really appreciate if anyone could assist with this.

    Many thanks,
    Mary

Topic Closed

This topic has been closed to new replies.

About this Topic