Jump to content

Getting blog content from childs child


Olli
 Share

Recommended Posts

Hey

I'm trying to output on my frontpage the latest news but I keep getting a output of "".

The sitemap looks something like this:

Homepage

-news page (uses template "news")

--news listed separately as children to "news page"

This is the probably the closest I have gotten to the right answer. So get the pages with template "news", which is just one page, and get the children of it. Am I missing something here?

<?php
foreach ($pages->get('template=news')->children as $news) {
?>
<h1><?php $news->title ?></h1>
<?php
}
?>

I have some dull information in the backend so I am expecting some 

output.

Any ideas?

Link to comment
Share on other sites

Inside that foreach, add another using $news->children as $news. I would give a better code example, but I'm on my mobile. :(

Sorry, I can't find the edit button on the mobile site. But I just noticed you aren't echoing out your title you need to use <?=$news->title?>

  • Like 1
Link to comment
Share on other sites

Well that was it :D I also got lost in my several template files but that final echoing fixed my problem :)

Now my next task is to sort them by date... we'll see if I need help with that too...

Edit: ("limit=3, sort=-date") seems to do most of the magic, just need to get the date sort to show latest first.

Edit: wrong syntax... ("limit=3, sort=-created") yey!

Edited by Olli
  • Like 1
Link to comment
Share on other sites

I'm getting the news content as wished but now I'm in trouble with the word count. As the foreach spits out the full length of the body text, I would need to limit this to e.g. 200 characters. Any ideas how that would be made with processwire or do I have to use normal php functions to limit it.

Alternatively, I could make 2 bodys, one where the intro text is and another for the full text, this is more work for the publisher tho...

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