Forum

Thread tagged as: Question

Displaying content on homepage from list/detail page

Hi there

Returning to Perch after a break and I'm rusty... I have two templates:

ht_poem_list.html

<perch:before>
<ul>
</perch:before>
    <li>
         <a href="poems.php?s=<perch:content id="slug" type="slug" />"><perch:content id="poem-title" type="text" /></a>
    </li>
<perch:after>
</ul>
</perch:after>

ht_poem_detail.html

<div class="poem-box">
    <h1>Words for <perch:content id="poem-season" type="text" label="Insert Season" required="true" title="true" /> <perch:content id="poem-year" type="text" label="Insert Year" required="true" title="true" /></h1>

    <h2><perch:content id="poem-title" type="text" label="Poem Title" required="true" title="true" /></h2>

    <perch:content id="poem-in-full" type="textarea" label="Poem in Full" html="true" editor="ckeditor" />

    <h3>by <perch:content id="poem-author" type="text" label="Poem Author" required="true" title="true" /></h3>

    <perch:content id="slug" for="poem-title" type="slug" suppress="true" />
</div>

<p><a href="index.php" title="Link back to the Archived Poems page">« Back to the Archived Poems page</a></p>

and I use the following on the poem index page to display a list of links which take you to the individual poem pages showing the full poem (season, title, poem in full, author)

<?php
    perch_content_create('Poems', array(
        'template'   => 'ht_poem_detail.html',
        'multiple'    => true,
        'edit-mode' => 'listdetail',
    ));

    perch_content_custom('Poems', array(
        'template' => 'ht_poem_list.html',
    ));
?>

This all works perfectly - the poem index page shows a list of link and each links to a detail page displaying the full poem and info.

I now want to display the latest poem , in full (season, title, poem in full, author - i.e just like the poem detail page), on the homepage. Would I use perch_content_custom in the same way?

Point me int he right direction please?

Thanks. Evie.

Evie Milo

Evie Milo 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, it's just the same.

perch_content_custom('Poems', array(
    'template'   => 'ht_poem_detail.html',
    'page' => '/path/to/poems.php',
    'count' => 1,
    'sort' => '_order',
    'sort-order' => 'DESC',
));

Thanks Drew - I'll give it a go - working on some other pages at the moment to try and get back into the swing of things and re-ignite my brain as I've not done any CMS stuff for months.

Super - got it working - my only issue is that on the poem detail page I have a link at the bottom of the page that links back to the poem list page - this link now appears on the homepage as it's in the poem detail template. Is there a way I can use an if/else statement to change the link, so if I'm on the poem detail page make a text link to go back to the poem list page (as it is now) - else I'm on the homepage, so change the text and link to go to the poem archive - still ilinking to the same page, but with different text and link url.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, do this:

PerchSystem::set_var('homepage', true);
perch_content_custom('Poems', array(
    'template'   => 'ht_poem_detail.html',
    'page' => '/path/to/poems.php',
    'count' => 1,
    'sort' => '_order',
    'sort-order' => 'DESC',
));

and then in your template:

<perch:if exists="homepage">
   ... this is used on the homepage
<perch:else />
   ... this is used everywhere else
</perch:if>

works a treat - thanks for the quick response - another thing struck off the to-do-list.