• indxMax

    (@indxmax)


    Hello,
    I need help with getting the page content with template elements applied.
    Lets say i have two pages created: page-1 and page-2.
    Now inside page-1 template(php code) I need to query for the content of page-2 with its template applied.
    At the moment I’m making cUrl requests by the page guid, but it makes the WP too slow because it is making requests through the internet.
    Since I’m not so advances with WP i thought maybe someone can help me with that? Is it even possible?

    foreach ($pages as $key) {
    	echo get_page_data($key->guid);
    }
    function get_page_data($url) {
    	$ch = curl_init();
    	$timeout = 2;
    	curl_setopt($ch, CURLOPT_URL, $url);
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    	$data = curl_exec($ch);
    	curl_close($ch);
    	return $data;
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • I don’t quite understand what you mean by “with its template applied”, but you can use get_page_by_path() to retrieve a particular page and its contents if you know its path. It will return a WP_Post object containing information such as title, excerpt, content, etc.

    If you just want to call a template file from within another template file, you can use get_template_part(). What this does is it pulls in the contents of one template file and sticks it in a particular spot. It works just like get_header() and get_footer(), and you can specify which template file you want to pull in.

    If what you need to do is read/write to local files, you can use WordPress’s Filesystem API:
    Filesystem API
    Tutorial: Using the WP_Filesystem
    WordPress Filesystem API: the right way to operate with local files

    Hope one of the above is helpful.

    Thread Starter indxMax

    (@indxmax)

    Those functions are useful, but not exactly what I need. Basically, I need to get the page which would be sent to website visitor. Meaning that I need to get the page content AND the template.
    For eg. lets assume I have two AP pages created
    example.com/page1
    example.com/page2
    Now I need to make a template for page1 which would also display page 2 with its content. So visitor would see both pages on one page.
    I hope it’s more clear now, if not please ask.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to get page content with template applied?’ is closed to new replies.