Section layout override

Your code modifications and patches you want to share with others.
Locked
nginx
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Mon Feb 22, 2010 1:43 pm

Section layout override

Post by nginx » Tue Mar 02, 2010 1:26 pm

Hello,

I have written a layout override for the section blog layout. The layout show echo the section's categories and for each category it should show the intro text of the first two articles and links to the rest.

The problem is that currently it shows me two intros of articles from the section according to some sort of internal indexing (not according to article id)

Here is the code:

Code: Select all

<?php
defined('_JEXEC') or die('Restricted access');


$rlu = array();
foreach ($this->items as $i => $item) :
    if (!isset($rlu[$item->catid])) :
        $rlu[$item->catid] = array();
    endif;
    $rlu[$item->catid][] = &$this->items[$i];
endforeach;

?>

<?php if ($this->params->get('show_page_title', 1)) : /*page title */?>
<h1 class="componentheading<?php echo $this->params->get('pageclass_sfx');?>">
    <?php echo $this->escape($this->params->get('page_title')); ?>
</h1>
<?php endif; ?>

<div class="contentdescription<?php echo $this->params->get( 'pageclass_sfx' ); /*section description*/ ?>">
<?php if ($this->params->get('show_description') && $this->section->description) : ?>
   <?php echo $this->section->description; ?>
<?php endif; ?>
</div>

<?php $cat = $this->categories[0]->id;?>

<?php foreach ($this->categories as $category) : /*start echoing the categories */ ?>
   <?php if ($category->id != $cat) {$cat=$category->id; echo "</div>";} ?>
   <div class="category<?= $cat ?>">
    <h2><?php echo $category->title;?></h2>
    <?php if ($category->description) : ?>
    <?php echo $category->description; ?>
    <?php endif; ?>
    <?php if (!empty($rlu[$category->id])) : ?>
    <ul>
        <?php $i=0; ?>
      <?php foreach ($rlu[$category->id] as $article) : /*drill down to category */ ?>   
        <?php if ($i<2) {$this->item =& $this->getItem($i, $this->params); echo $this->loadTemplate('item'); $i++;} else { /*first two articles*/ ?>
      <li>
           
         <a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article->catslug, $article->sectionid)); ?>">
                <?php echo $article->title; ?></a>
        </li>
      <?php } ?>
        <?php endforeach; ?>
    </ul>
    <?php endif; ?>
<?php endforeach; ?>
</div>
How can I achieve that?

Thanks a lot,
Alexander

P.S

Thanks a lot to Andrew http://www.theartofjoomla.com/home/6-la ... tents.html

The override is mainly his work here :-)

User avatar
imanickam
Joomla! Master
Joomla! Master
Posts: 27300
Joined: Wed Aug 13, 2008 2:57 am
Location: Chennai, India

Re: Section layout override

Post by imanickam » Tue Mar 02, 2010 1:39 pm

In that menu item that is of the type Section Blog Layout, try to set the following parameters available in the Parameters (Advanced).

Category Order - No, Order by Primary Order Only
Primary Order - choose an option to suit your need
Ilagnayeru (MIG) Manickam | இளஞாயிறு மாணிக்கம்
Joomla! - Global Moderators Team | Translations Coordination Team | Tamil (தமிழ்) Translation Team

Eegan - Support the poor and underprivileged

nginx
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Mon Feb 22, 2010 1:43 pm

Re: Section layout override

Post by nginx » Tue Mar 02, 2010 1:56 pm

imanickam wrote:In that menu item that is of the type Section Blog Layout, try to set the following parameters available in the Parameters (Advanced).

Category Order - No, Order by Primary Order Only
Primary Order - choose an option to suit your need
Yes, but how is it going to force the override above to show the intros of the first two articles from each CATEGORY and not just some articles from the SECTION?

User avatar
imanickam
Joomla! Master
Joomla! Master
Posts: 27300
Joined: Wed Aug 13, 2008 2:57 am
Location: Chennai, India

Re: Section layout override

Post by imanickam » Tue Mar 02, 2010 3:27 pm

It is not... Probably, you have to change the Category Order also.

However, the challenge is going to be browsing through the whole result set and choose the appropriate ones. There is some programming involved like setting and resetting variables.

Alternatively, you may have to change the Joomla! core file, most likely the file section.php located in the directory \components\com_content\models where you have to change the where clause that contains sub-query.
Ilagnayeru (MIG) Manickam | இளஞாயிறு மாணிக்கம்
Joomla! - Global Moderators Team | Translations Coordination Team | Tamil (தமிழ்) Translation Team

Eegan - Support the poor and underprivileged

nginx
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Mon Feb 22, 2010 1:43 pm

Re: Section layout override

Post by nginx » Mon Mar 08, 2010 10:44 am

imanickam wrote:It is not... Probably, you have to change the Category Order also.

However, the challenge is going to be browsing through the whole result set and choose the appropriate ones. There is some programming involved like setting and resetting variables.

Alternatively, you may have to change the Joomla! core file, most likely the file section.php located in the directory \components\com_content\models where you have to change the where clause that contains sub-query.
Easier option: use $article->introtext and that's it.

Solved

User avatar
imanickam
Joomla! Master
Joomla! Master
Posts: 27300
Joined: Wed Aug 13, 2008 2:57 am
Location: Chennai, India

Re: Section layout override

Post by imanickam » Mon Mar 08, 2010 1:54 pm

Glad to know that you could implement the feature you want.
Ilagnayeru (MIG) Manickam | இளஞாயிறு மாணிக்கம்
Joomla! - Global Moderators Team | Translations Coordination Team | Tamil (தமிழ்) Translation Team

Eegan - Support the poor and underprivileged


Locked

Return to “Core Hacks and Patches”