Posts: 34
Threads: 13
Joined: Nov 2010
2010-11-27, 04:55:22
(This post was last modified: 2010-11-27, 04:56:18 by evilmind.)
Hi. Can anyone tell me how to capture the text (content) inside a GetSimple page so another php page can display it? I'm looking for a <?php include statement that I can use.
Thanks in advance for any help you can give me.
Don
Posts: 972
Threads: 27
Joined: Aug 2009
Pitching together some stuff from
a different topic and
code from the SVN I would add a function something like this:
Code:
function get_content($page,$echo = true) {
if ($thisfile = file_get_contents(GSDATAPAGESPATH.$page.'.xml')) {
$data = simplexml_load_string($thisfile);
$content = stripslashes(htmlspecialchars_decode($data->content, ENT_QUOTES));
if ($echo) echo $content;
return $content;
}
}
Add this anywhere in your code (possibly in
the theme’s functions.php file) and you can start including other pages by calling the function as:
Code:
<?php get_content('slug'); ?>
Switch
slug for the slug of the page you want to include.
As a little extra, if you want to put the content of the page in a PHP variable you can do the following:
Code:
$variable = get_content('slug',false);
This will suppress the PHP echo.
I hope this helps!
Posts: 2
Threads: 0
Joined: Apr 2011
Hi, I need to get also the HTML assigned to that page.. how I can do it?
Thank you in advance.
Posts: 2,928
Threads: 195
Joined: Feb 2011
beat84 Wrote:Hi, I need to get also the HTML assigned to that page.. how I can do it?
Thank you in advance.
Beat, the pages are in XML format and they are stored in /data/pages
so any php script which deals with XML format can read that and do with the content what it wants (what you want)
but you cannot expect to get a complete solution for this here, but the net is full with tutorials for that
for example:
http://www.ibm.com/developerworks/library/os-xmldomphp/
Posts: 2
Threads: 0
Joined: Apr 2011
I solved in this way:
Code:
echo file_get_contents($url)
I hope this can help.
Thanks