Jump to content

Get child pages of pages using a certain template?


antknight
 Share

Recommended Posts

I would like to get all the child pages of the news-month-archive template sort them by -news_date and limit to 10 per page. This is what I have at the moment:

<?php 
      $results = $pages->find("template=news-item, sort=-news_date, limit=10"); 
      $pagination = $results->renderPager(array(
      'numPageLinks' => "5",
      'nextItemLabel' => "Next",
      'previousItemLabel' => "Prev",
      'listMarkup' => "<ul class='MarkupPagerNav'>{out}</ul>",
      'itemMarkup' => "<li class='{class}'>{out}</li>",
      'linkMarkup' => "<a href='{url}'><span>{out}</span></a>"));
      echo "<ul class='list'>";
      foreach($results as $result) {
        echo "<li class='list-item'>";
        echo "<section>";
        echo "<h5><a href='{$result->url}'>{$result->title}</a></h5>";
        echo "<em>{$result->news_date}</em>";
        if($result->body) {
        $summary = substr($result->body, 0, 150); 
				if(($pos = strrpos($summary, ".")) !== false) {
				$summary = substr($summary, 0, $pos); 
				};
        echo "<p>{$summary} <a href='{$result->url}'>...more</a></p>";
      	}
        echo "</section>";
      }      
      echo "</ul>";
      echo $pagination;
      ?>

How can I rewrite the selector to achieve this?

I tried 

$results = $pages->find("template=news-month-archive")->children("sort=-news_date, limit=10"); 

but I get a server error?

Many Thanks

Link to comment
Share on other sites

The result of the find is an array, so you can't get the children of it. If there's only one page with that template you can do:

$results = $pages->get("template=news-month-archive")->children("sort=-news_date, limit=10"); 
  • Like 4
Link to comment
Share on other sites

So there are two selectors I need:

One to grab all pages that are children of the news-month-archive template site wide.

One to grab all pages that are children of the news-month-archive template in the current rootParent

Anybody help me out?

Link to comment
Share on other sites

One to grab all pages that are children of the news-month-archive template site wide.
$pages->find("parent.template=news-month-archive"); 
One to grab all pages that are children of the news-month-archive template in the current rootParent
$page->rootParent->find("parent.template=news-month-archive"); 
  • Like 6
Link to comment
Share on other sites

  • 6 years later...

Hi guys, I'm having a problem with multiple-languages.

I want to make a list of all the children of one page even if the title field has been only populated in one of the languages, yet the link should point to the page in the currently selected language.

Didn't figure out yet :(.... 

Link to comment
Share on other sites

Well, there are two things to watch out for:

  • Is the page activated in the alt. language?
  • How is the title-field configured in the alt. lang. page version?

At field-level, you can define the behaviour of what's shown, in the details-tab:

multilang-options.PNG.02ad998082b45f156edcdb03a08d3807.PNG

If you use the option shown above, you still have to make sure the alt. lang. page version is activated.

Link to comment
Share on other sites

Hi Dragan, I started working from the multi-language profile.

the field is "Title (multi-language)" and it has "Inherit value from default language" on.

Although the page's children can be created from another page using a field (page reference). which seems to only populate the english field.

27 minutes ago, dragan said:

alt. lang. page version is activated

I'm not sure I understand the alt lang version.

 

Link to comment
Share on other sites

1 hour ago, Macaco said:

I'm not sure I understand the alt lang version.

I mean this:

langs-activated.thumb.PNG.33d0be8addde6e769270d23139ef5c8f.PNG

note the "active" checkboxes.

1 hour ago, Macaco said:

Although the page's children can be created from another page using a field (page reference). which seems to only populate the english field.

OK, now I know a bit better what you mean. These pages are not created "manually" in the admin, but from a page-reference field that has the option "allow to create new pages?" in the field settings.

If that is indeed the case, I wouldn't know what the expected / default behavior would be. Only create the page in the default language? (which seems to be the case). I don't know if that is configurable. I don't have time right now to investigate - maybe you'd have to use a hook to automatically activate all languages when creating a new page like that.

  • Like 1
Link to comment
Share on other sites

Ah! You are right, when I create a new page"manually", it comes as "active" by default. But when the page is created from page-reference it doesn't.

I'm gonna look into the hook.

Thank you Dragan, 

PS. apologies for using the wrong thread, I guess it should be in multi-language.

 

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...