Hi all, using some code from an older thread if anybody was involved, thanks.
Ok, with the code below I’m basically selecting all pages and their child pages from the navigation database. What I need, and trying now is only show a selection of these pages based on the values from a xml file.
// get all pages
$pages = new TFW_Navigation($pageNav);
$pages = $pages->getNavigation();
foreach ($pages as $index => $topPage)
{
// get all child pages
$children = $topPage->getChildren(null,true);
if (!empty($children)) {
foreach($children as $child) {
I need to update my initial php code somehow to only show the pages with the IDs from related_articles. So instead of displaying all the pages from the database, only show the ones in the xml file.
Can anybody advise or offer suggestions how I could do this?
So, what you want exactly, you want to get articles from database based on the xml file with the close values?
So, if in the xml file are values as 22 and 29, you want to only get articles from database based on these values?
<?php
$xml = simplexml_load_file($docRoot.'article/data/'.$pageID); or trigger_error("Error: Cannot create object");
foreach($xml->value as $items) {
// do what you want to do here.
echo $items.'<br>';
}
?>
I want to load only the pages from $pages based on the values inside related_articles. The xml file is full of data and has many values for different elements. I need to reference the relate_articles. How do I fit this into the original pages and child pages logic above?
Simply, you have to include that part of code in this foreach loop, so for every item, the code will get the required page.
A question,
$pages = new TFW_Navigation($pageNav);
The $pageNav value is an integer( a number ) ? if it is, all you have to do is to replace here the $pageNav with $items.
foreach($xml->value as $items) {
// get all pages
$pages = new TFW_Navigation($items);
$pages = $pages->getNavigation();
foreach ($pages as $index => $topPage)
{
// get all child pages
$children = $topPage->getChildren(null,true);
if (!empty($children)) {
foreach($children as $child) { }
}
}
}
I just started with xml, I am not that good, just give me a little time to search for what you need.
If the value field is just part of the parent related_articles, then there is no problem, but if this field is used in other parts of that xml file, then there is a problem, have you found a solution?
Been trying everything, no errors, but no articles no content is showing?
Yes I think its an integer, I’ve used your code and seems to run ok, though as above, nothing is showing.
How does it know to access the related_articles element from the XML file?
We don’t mention it.
Have you included the line with loading the xml file? that line has to be the first line and above the foreach loop with the rest of the code.Yeah, I am not sure, I am quite new to xml ( SimpleXML).I am thinking at a solution.
Not yet.
As above in my first post, each article has different related articles, this is just one element of about 30 from the xml file, thats why if we don’t mention related_articles, we could be calling any value, if that makes sense.
So the code above is unique( with all the value tags), I mean, the value tag is only in related_articles, if it is, then there is no problem, if we use $xml->value, only all the tags with the value name are used, no other tags.I think there is a problem somewhere else, try something simple, see if this works:
<?php
$xml = simplexml_load_file($docRoot.'article/data/'.$pageID); or trigger_error("Error: Cannot create object");
foreach($xml->value as $items) {
// do what you want to do here.
echo $items.' ';
}
Test just this code.
Yes looking myself, lots of diffrent ways of doing stuff, though still, surely there is an easy why to add related_articles into, even then, no guarantee this will work:
foreach($xml->value as $items) {
I’ve just tried:
foreach($xml->related_articles as $itemsA) {
foreach($itemsA->value as $items) {