[resolved] Include Page Content without Loop (9 posts)

  1. mc_marie
    Posted 3 years ago #

    So I've been using the code posted here: http://wordpress.org/support/topic/use-text-from-my-word-press-page-elsewhere-on-my-website?

    However, it doesn't work if the page desired is anything other than a main page.

    Does anyone have a similar trick that I could use for displaying sub-page (or sub-sub page) content without using the loop?

  2. Justin Greer
    Forum Moderator
    Posted 3 years ago #

    Why would you not want to use the loop. It has everything you need and is not bloated?

  3. wpismypuppet
    Posted 3 years ago #

    Can you give a more details on what you are trying to accomplish? Where are you using that code? Do you have one static page that is pulling content from your WordPress site? Are you using multiple pages? Can you send a link to your existing site where the problem resides? Can you maybe show some code?

    I believe I can help you with this, but right now it's too vague for me to know where to begin.

  4. mc_marie
    Posted 3 years ago #

    We are displaying the page content on an archive page in a specific section. You can see it working here on a category-ID.php while the page of desired content is at the main level. However, for several reasons, we want the page of desired content to be a sub-page of Churchs & Organizations.

    I have also used this code in other ways when I'm trying to display page content in another page template or something of that sort.

    <?php //including text from a page without using the loop! without loop outside of loop page content
    		include "wp-load.php";
    		$page = get_page_by_path('church-resources'); //slug of desired page
    		echo apply_filters('the_content', $page->post_content);?>
  5. wpismypuppet
    Posted 3 years ago #

    That code you are using should work completely fine anywhere on your website. What might not be working is your include statement. Are you getting any error messages when doing this? Also, if a page you are using is already a part of WordPress... ie inside your theme's folder... you don't need to include wp-load.php. this is only if you are physically outside of the WordPress directory.

  6. mc_marie
    Posted 3 years ago #

    So it's true that I don't need the include statement, but I still can't use this code unless the page is a main level page.
    Thoughts on why this could be working this way?

  7. wpismypuppet
    Posted 3 years ago #

    No, you can... you just need to include the path to the child page. Let's say "church-resources" is a child page of "about-us"... then you would write:

    	$page = get_page_by_path('about-us/church-resources');
    	echo apply_filters('the_content', $page->post_content);
  8. mc_marie
    Posted 3 years ago #

    tried that - didn't work.
    (just tried again) and it works. I must have had my parent page slug wrong the first time!

    Thanks for all of your help!

  9. wpismypuppet
    Posted 3 years ago #

    You are welcome... it could have also been the include statement causing a PHP error, which then caused the rest of the code to fail as well. Glad I could assist!

Topic Closed

This topic has been closed to new replies.

About this Topic