Forum

Thread tagged as: Question, Discussion

How to link multiple sections with single setup page.

Hi,

I have been working for a website & stuck with an implementation that how can I setup latest news sections (just top 5 headlines with some content) on home page and another webpage 'News' where all the news headline with the complete content is displayed.

So the question here is; how can I have the setup done for 'News' webpage so that it displays all the content in the same page but show only top 5 headlines from these news on the home page.

Sooner reply would be appreciated. Thanks!

Damian McCracken

Damian McCracken 0 points

  • 5 years ago
Simon Clay

Simon Clay 127 points

Hi Damian, this is quite easy to do.

Firstly, set up your news page, e.g. news/index.php, to contain something like:

<?php

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


     if (perch_get('s')) {

          // Detail mode
          perch_content_custom('News', array(
               'template' => 'article.html',
               'filter'   => 'slug',
               'match'    => 'eq',
               'value'    => perch_get('s'),
               'count'    => 1,
          )); 

     } else {

          // List mode
          perch_content_custom('News', array(
               'template' => '_news_listing.html',
          )); 
     }

?>

The above uses the article.html template that already exists in perch/templates/content, with the addition of a slug for linking to the full article, but you can use your own if you like. Here it is with the `slug added:

<h2><perch:content id="heading" type="text" label="Heading" required="true" title="true" /></h2>
<p class="date"><perch:content id="date" type="date" label="Date" format="%d %B %Y" required="true" /></p>

<perch:content id="body" type="textarea" label="Body" markdown="true" editor="markitup" required="true" />

<p class="vcard">
    © <perch:content id="date" type="date" label="Date" format="Y" />

    <span class="fn n">
        <perch:content id="author_given_name" type="text" label="Author given name" />
        <perch:content id="author_family_name" type="text" label="Author family name" /> 
    </span>  
</p>

<perch:after>
  <perch:if exists="paging">
    <div class="paging">
      Page <perch:content id="current_page" type="hidden" /> of <perch:content id="number_of_pages" type="hidden" />
      <perch:if exists="not_first_page">
        <a href="<perch:content id="prev_url" type="hidden" encode="false" />">Previous</a>
      </perch:if>
      <perch:if exists="not_last_page">
        <a href="<perch:content id="next_url" type="hidden" encode="false" />">Next</a>
      </perch:if>
    </div>
  </perch:if>
</perch:after>

<perch:content id="slug" for="heading" type="slug" suppress="true" />

Your _news_listing.html (to be saved in perch/templates/content/) template would contain any elements ofarticle.html` you'd like to show in the listing, in list form. For example, just the headline:

<perch:before>
<ul>
</perch:before>
    <li><a href="/news/index.php?s=<perch:content id="slug" for="heading" type="slug"/>"><perch:content id="heading" type="text" label="Heading" required="true" title="true" /></a></li>
<perch:after>
</ul>
</perch:after>

On the website home page, add this code to show the latest 5 News links:

<?php
    perch_content_custom('News', array(
         'page' => '/news/index.php',
         'template' => '_news_listing',
         'count' => 5
    ));
?>
Rachel Andrew

Rachel Andrew 394 points
Perch Support

What you are describing is a list detail page, there is an example in the documentation https://docs.grabaperch.com/perch/content/functions/how-do-i-create-list-detail-pages/

you have any video for this :( ??

Drew McLellan

Drew McLellan 2638 points
Perch Support

No - are you having problems following the instructions? Where are you stuck?