Support » Fixing WordPress » Include Page Content without Loop

Viewing 8 replies - 1 through 8 (of 8 total)
  • Moderator Dash10

    (@justingreerbbi)

    Forum Moderator

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

    wpismypuppet

    (@wordpressismypuppet)

    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.

    mc_marie

    (@mc_marie)

    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
    		//http://wordpress.org/support/topic/use-text-from-my-word-press-page-elsewhere-on-my-website
    		include "wp-load.php";
    		$page = get_page_by_path('church-resources'); //slug of desired page
    		echo apply_filters('the_content', $page->post_content);?>

    wpismypuppet

    (@wordpressismypuppet)

    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.

    mc_marie

    (@mc_marie)

    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?

    wpismypuppet

    (@wordpressismypuppet)

    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:

    <?php
    	$page = get_page_by_path('about-us/church-resources');
    	echo apply_filters('the_content', $page->post_content);
    ?>
    mc_marie

    (@mc_marie)

    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!

    wpismypuppet

    (@wordpressismypuppet)

    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!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Include Page Content without Loop’ is closed to new replies.