Jump to content

How do you show child pages without titles


OpenBayou
 Share

Recommended Posts

I have three pages under a child page under a child page.

Deals
- Store
- - page 1
- - page 2

How do I show the title of page 1 and page 2?

Thanks.

This is how I have the template:

<?php foreach($pages->find("parent=deals") as $child) { ?>
<?php echo $child->title;?>
<?php }?>

 

Link to comment
Share on other sites

If you have the 'Deals' page, you can with $page->children get the 'store' page. Then get the children of the store page and output the title:

$store = $pages->find("parent=deals");
echo "$store->title";
$storechild = $store->children;
foreach ($storechild as $child){
	$content .= $child->title;
	// OR echo "$child->title";
}
Edited by Harmen
Updated
  • Like 3
Link to comment
Share on other sites

8 hours ago, Harmen said:

$store = $pages->find("parent=deals");

Not to nitpick, but remember that $pages->find will give you a pageArray so it is possible that the $store->title might not work how you'd expect. If another child of Deals exists, then you might run into some errors. It would be better to use either $pages->findOne or $pages->get. If you anticipate that Deals might have more child pages, I would suggest expanding the selector as well.

  • Like 2
Link to comment
Share on other sites

12 hours ago, Harmen said:

If you have the 'Deals' page, you can with $page->children get the 'store' page. Then get the children of the store page and output the title:


$store = $pages->find("parent=deals");
echo "$store->title";
$storechild = $store->children;
foreach ($storechild as $child){
	$content .= $child->title;
	// OR echo "$child->title";
}

Didn't work.

Link to comment
Share on other sites

<?php $store = $pages->get("parent=/deals/");
$storechild = $store->children;
foreach ($storechild as $child){?>
	<?php echo $child->title;?>
<?php } ?>

The above code does show sub-pages under Page A but sub-pages under Page B and C, it only shows 'Sub-page A Sub-page B'. This is how it's structured:

Deals
- Page A
- - Sub-page A
- - Sub-page B
- Page B
- - Sub-page A
- Page C
- - Sub-page A

 

Link to comment
Share on other sites

$pages->get() will always get you ONE page only. In your case, it gets you the first child of $store, i.e. Page A. This is because Page A, via sorting, comes first (i.e. before Page B and Page C. $pages->get() returns a Page.

If you did a $pages->find(), this will always return several pages (if it found them, of course). The important thing, as noted earlier, is that $pages->find() returns a PageArray. That means, several Page Objects. So, you cannot  directly echo like so:

$results = $pages->find('template=basic-page');
// cannot do this; it doesn't make sense since you have multiple items inside $results
//...so, you would need to loop through it using a foreach
echo $results->title;

Think of it this way:

// FRUIT: this is very specific. You are requesting a banana; not an orange, not an apple, but a banana.
//...We will get you a banana
$fruit = $pages->get('banana');// @note: pseudo code!
// hence, you can do
echo $fruit->title;// outputs 'banana'

// BUT....if you want FRUITS...there are several fruits...
$fruits = $pages->find('fruits');// @note: pseudo code!
// if you did this, the question would be, what fruit was that again?
// direct 'echo' doesn't make sense;
// ...you need to tell us what fruit you want; apple? orange? banana? There's several fruit in here!
echo $fruits->title;
// aaah, so, we loop through the basket, one fruit at a time...
foreach($fruits as $fruit) echo $fruit->title;// this will output each fruit in here in turn...apple; orange, banana, etc...

Hope this makes sense.

Edited by kongondo
  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...