Fetching a list of pages and display as a list.

Permalink
Hi
I have article page, which has the blocks Title,Description,Content,Image
the structure is like that:
site.com/articles/my-first-article
site.com/articles/my-second-article

IN THE HOMEPAGE I want to show a list of articles (everything under "site.com/articles") ordered by date added DESC.
I want to actually show the title and the description with a link to the relevant page.

Whats the best way to do this?
I did not find any example that get pages for a certain parent ("articles"), more over, every fetch that I did is not coming with the blocks.

Thanks

 
hutman replied on at Permalink Reply
hutman
You should be able to do this with the Page List block, that allows you to select which parent page you want to grab pages from and if you want to show title/description.
fatnjazzy replied on at Permalink Reply
I was asking for a code sample.
thanks
fatnjazzy replied on at Permalink Reply
I was asking for a code sample.
thanks
hutman replied on at Permalink Reply
hutman
There is no code needed, here is a quick screencast of how to do it.

https://drive.google.com/file/d/0B6ozhYHiHGq6SEFVQ2pJMjF4ZFU/view...
fatnjazzy replied on at Permalink Reply
Thank you, but this allow me only to show attributes and not blocks.
I prefer to do this via code BTW.
Thanks
hutman replied on at Permalink Reply
hutman
The blocks that you named are used to fill attributes, but here is the 5.6 documentation for the PageList code, it is 99% the same

http://legacy-documentation.concrete5.org/developers/pages/searchin...

And here is some information on getting blocks from a page

http://legacy-documentation.concrete5.org/developers/blocks/working...
fatnjazzy replied on at Permalink Reply
Here is where I got to till now,maybe youll understand me better (-:
$list = new \Concrete\Core\Page\PageList();
            $list->filterByName("article");
            $pages = $list->getResults();
            for($i =1; $i<=2;$i++){
                $t = \Concrete\Core\Page\Page::getById($pages[$i]->cID);
                $b = $t->getBlocks("MainImage");
                var_dump($b[0]);//how to display the field
            }
.

The last line will output the block, which is good, but how to I display it?

this:

$b[0]->display($c);

will result the error: Object of class Concrete\Core\Page\Page could not be converted to string

(remember, Im in the homepage)
hutman replied on at Permalink Reply
hutman
$b[0]->display($t);


$t is your page object, not $c
fatnjazzy replied on at Permalink Reply
tried that )-:
I got:
Object of class Concrete\Core\Page\Page could not be converted to string
hutman replied on at Permalink Reply
hutman
What happens if you do

$b[0]->display();
fatnjazzy replied on at Permalink Reply
Call to a member function display() on null
this is odd
$b[0] is not null...
hutman replied on at Permalink Reply
hutman
I think this is what you want

$list = new \Concrete\Core\Page\PageList();
$list->filterByName("article");
$pages = $list->getResults();
foreach($pages as $page){
    $blocks = $page->getBlocks("MainImage");
    if(count($blocks) > 0){
        foreach($blocks as $block){
            $block->display();
        }
    }
}


This is assuming that the Area Name you are trying to get blocks from is the MainImage area.
fatnjazzy replied on at Permalink Reply
Thank you for your time.
Works perfect!!!!
Thanks again!