Forum

Thread tagged as: Question

Mixed listing page with content custom

Hi Drew/Rachel,

I have a Perch site where I am listing projects with a certain category as show below:

<?php
perch_content_custom('Projects', array(
    'page' => '/project.php',
    'template' => 'project_listing_cgi.html',
    'category' => array('project-tag/cgi'),
));
?>

My client wants to add 'Quotes' to the site that are show as part of the same listing above. The quotes are not related to a project but they want to disperse them within the project listings.

Is there any way of doing this in Perch?

This is the code for project.php

<?php

perch_content_create('Projects', array(
    'template'   => 'project_detail.html',
    'multiple'    => true,
    'edit-mode' => 'listdetail',
));

perch_content_custom('Projects', array(
    'template' => 'project_detail.html',
    'filter' => 'slug',
    'match' => 'eq',
    'value' => perch_get('s'),
    'count' => 1,
));

?>
Andy Knight

Andy Knight 1 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

To what level do you need to control how they're interspersed? Is it something like a quote after every 3 items? Or does it need to be manual?

Hi Drew,

Ideally it would be manual.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I can't think of a good way to do that.

OK, thanks Drew.

Would it change things if we were to intersperse every 5th item or so?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, you'd fetch the regions using the split-items option and then loop through and intersperse them.

Hi Drew,

Client is happy to intersperse every 5th item but I am struggling to find any documentation on the split-items option.

I assume I need to use something like this:

<?php
    perch_content_custom(array('Projects', 'Quotes'), array(

    )); 
?>

But that is where I get lost - how would I: a) Pull in content from two pages b) Use different templates to display Projects and Quotes c) Intersperse them where listed

Thanks in advance, Andy

Drew McLellan

Drew McLellan 2638 points
Perch Support

split-items uses the template as normal, but returns an array of the individual HTML blocks. This enables you to loop through them and manipulate or output as required.

Anyway. Something like:

$projects = perch_content_custom('Projects', array(
        'split-items' = > true,
    )); 

$quotes = perch_content_custom('Quotes', array(
        'split-items' = > true,
    )); 

for ($i=0; $i<count($projects); $i++) {
    echo $projects[$i];
    if ($i % 5 === 0) {
        if (count($quotes)) {
            echo array_shift($quotes);
        } 
    }
}

Thanks Drew,

I'll give this a go :)