WordPress.org

Ready to get started?Download WordPress

Forums

How to pull the content of a page from the current ID (10 posts)

  1. sixfootjames
    Member
    Posted 2 years ago #

    Hi,

    I have a template I am using called General Content, which will be used for all other pages except for the home page.

    I am trying to pull the content of the pages into this template of that specific page. Here's what I have tried.

    • Basing my template page on page.php
    • Various forms of The Loop
    • And eventually this option...
    <div class="layout">
    		<?php
    			$page_id = 26;
    			$page_data = get_page( $page_id );
    			echo '<h3>'. $page_data->post_title .'</h3>';
    			echo apply_filters('the_content', $page_data->post_content);
    		?>
          </div>

    This works based on the example from the codex but what I would like is is to set a the page_id to the current page

    Something like this:
    $page_id = $page->ID;

    Many thanks

  2. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    try:

    $page_id = $post->ID;

    if this works might depend on what is going on otherwise in the template.

  3. sixfootjames
    Member
    Posted 2 years ago #

    Hi alchymyth,

    I had tried this option before but it didn't work either.
    Is there any other way of pulling content from pages that you know of?

    Thanks

  4. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    any other way of pulling content from pages

    the normal loop should do this;

    however, this will depend if there is any other code before the loop - this could be in header.php, sidebar.php, or from a plugin.

    are you referring to a static page with 'the current page'?

    template I am using called General Content

    is that a page template, and what is the full code of that template?
    (please paste the code into a http://pastebin.com/ and post the link to it here)

    http://codex.wordpress.org/Pages#Page_Templates

    what theme are you using?

  5. sixfootjames
    Member
    Posted 2 years ago #

    Hi Alchymyth,

    I started this project from scratch, in order to learn a lot more and not base my knowledge on Frameworks which I have done in the past.

    The General Content page is a template page I normally build that will hold most generic content of a site. Most often, a two column page and is not the home page

    I have tried the normal loop...varying option thereof too. :)

    Here's the PasteBin code: http://pastebin.com/F5EwabTf

    Thanks for the help!

  6. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    what is the actual output of the code?

    nothing?
    some wrong post or page?

    unless there is another query in header.php, and you can identify what it does,
    try to add <?php wp_reset_query(); ?> before line 13

  7. sixfootjames
    Member
    Posted 2 years ago #

    At the moment nothing Alchymyth.

    What it should putput is just the page content. On home page of the site (localhost) I can pull the content I need but for all other normal pages, I just need for the the pages' content to pull into the "General Content" template.

    I did see another post like you are suggesting here, let me try that again and see if anything comes of it.

    Will get back to you again..thanks :)

  8. sixfootjames
    Member
    Posted 2 years ago #

    At the moment nothing Alchymyth.

    What it should putput is just the page content. On home page of the site (localhost) I can pull the content I need but for all other normal pages, I just need for the the pages' content to pull into the "General Content" template.

    I did see another post like you are suggesting here, let me try that again and see if anything comes of it.

    Will get back to you again..thanks :)

  9. sixfootjames
    Member
    Posted 2 years ago #

    That did the trick, thanks Alchymyth.

    This worries me a little though, as I'd like to get this right for future projects. Could I post my header.php and functions.php file to have a look at where I might be going wrong?

    Both are not long pages of code....yet :)

    Many thanks again for all your help! Going forward, I will use this method of resetting the query, should something go wrong.

  10. sixfootjames
    Member
    Posted 2 years ago #

    Hi Alchymyth,

    If you don't mind, would you please have a look where I might have gone wrong here? I assume, it must be in my header that I've gone wrong or in the functions.php file?

    Header: http://pastebin.com/1h1WXLLP
    Functions: http://pastebin.com/VPf6YBcS

    Many thanks again

  11. sixfootjames
    Member
    Posted 2 years ago #

    Just checked another project I worked on, turns out I was resetting the query every time I pulled something from the DB, so now the normal Loop IS working!

    Many thanks again Alchymyth

Topic Closed

This topic has been closed to new replies.

About this Topic