Forum

Thread tagged as: Question, Problem

Perch_Content_Custom - Replace page path with variable

Hi there,

Just wondering of it is possible to make the the page value within the perch_custom_content function dynamic. That is to say, I have a template using the custom content function and I want it to bring back specific content given the page selected.

My current function looks like this:

$industry = perch_content_custom('ISSUE', array(
    'page' => '/q4-2014-contents.php',
    'template' => 'issue-listing-industrynews.html',
    'filter'=>'articleSection',
    'match' =>'eq',
    'value' => 'B',
    'sort'=>'articleSection',
    'sort-order'=>'DESC',   
       .......etc etc
       },
));

I am suing perch_page_url to get the required path and storing this as a variable:

$url = perch_page_url(array(
    'include-domain' => false,
), true);

$uri = ltrim($url, '/');

I now want to 'inject this into my perch_content_custom function, as such:

$industry = perch_content_custom('ISSUE', array(
    'page' => $uri,
    'template' => 'issue-listing-industrynews.html',
    'filter'=>'articleSection',
    'match' =>'eq',
    'value' => 'B',
    'sort'=>'articleSection',
    'sort-order'=>'DESC',   
       .......etc etc
       },
));

Any ideas how I can achieve this ?

All the best,

Andy

Andrew Kennedy

Andrew Kennedy 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

That should work. Is it failing?

Yes, it's just not returning any results. But if I replace $uri with a value, say my '/q4-2014-contents.php'...ohh hang on !

What a turnip ! Funny how you suddenly see things when you leave for awhile and then come back.

I went to all the trouble of:

$url = perch_page_url(array(
    'include-domain' => false,
), true);

$uri = ltrim($url, '/');
echo $uri;

...when of course I need the first forward slash to give it scope !

Not sure why I got it into my head that I needed to remove it.

Grrr, still, glad that what I thought should work does.

Sorry Drew. Hopefully this helps someone out, under 'things to look out for'.