Forums

Get Page Content - Custom Template (2 posts)

  1. jumust
    Member
    Posted 1 year ago #

    Hi I'm using the code below in a custom template to grab the content written in a specific page (in this case is the number 312).

    How can I grab the content of every pages which I use this template in, without use the page ID, but something like "all pages"?

    <?php
    $page_id = 312; // 312 should be replaced with a specific Page's id from your site, which you can find by mousing over the link to edit that Page on the Manage Pages admin page. The id will be embedded in the query string of the URL, e.g. page.php?action=edit&post=123.
    $page_data = get_page( $page_id ); // You must pass in a variable to the get_page function. If you pass in a value (e.g. get_page ( 123 ); ), WordPress will generate an error. 
    
    $content = $page_data->post_content; // Get Content
    $title = $page_data->post_title; // Get title
    echo $page_data->post_content; // Output Content, echo $page_data->[Page data field] (see above)
    ?>

    Thanks

  2. Chilaxnanananananana
    Member
    Posted 1 year ago #

    I have been looking over and over for the answer to this. I too would like to know how to do this. Does anyone know?

Topic Closed

This topic has been closed to new replies.

About this Topic