• 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

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Get Page Content – Custom Template’ is closed to new replies.