Question

How can I show the full text of a leading article (even if it contains a read more) on a Category Blog Layout?

Is there a back-end setting I can change or which PHP file do I need to overwrite? I only want the leading article's fulltext to show, intro articles should still display the readmore with only intro text.

Thanks in advance.

Was it helpful?

Solution

You don't specify which version of Joomla! so this reply is based on 2.5.x

You will need to create a layout override for com_content, specifically for the category view tmpl file blog.php or blog_item.php.

If your template already has an override installed for com_content you will find it at this location:

/templates/your-template/html/com_content/category/

If not you can copy the original files from your Joomla! 2.5's component directory at /components/com_content/views/category/tmpl/

In that directory you will find a series of files starting with blog and ending with .php - you can override 1 or all of these by coping them to the first path listed above. N.B. Only copy the files you need to change Joomla! is smart enough to look in the default directory if it doesn't find a version in the overrides location.

The default Joomla! 2.5 installation has these blog files:

blog_children.php
blog_item.php
blog_links.php
blog.php

Basically blog.php is the main file and it includes the sub-layouts like blog_item.php as required.

If you're working from the default Joomla! 2.5 files, to achieve your goal you will probably have to override blog.php and blog_item.php and find a way to check whether you are in the leading item. Once you know that your in a leading item you will then want to echo out the full text of the item.

blog_item.php normally just outputs the intro text with a line like this:

<?php echo $this->item->introtext; ?>

You'll want to have the full text echo'd so after you've wrapped the line above in an if to check if you're doing the leading item your output line will look something like this:

<?php echo $this->item->introtext.$this->item->fulltext; ?>

Note: I've haven't check this works it's just speculation and relies on the $item having the full row from the #__content table.

So the articles full text isn't added to the article item in a standard install i.e. you can simply echo $this->item->fulltext.

There are two ways to get the full text.

The simplest & first is to modify the core file at /components/com_content/models/articles.php starting with the first $query->select() in the function getListQuery() which starts on/near line 153. Add ' a.fulltext,' after the a.introtext and before the single apostrophe, so the line looks like this:

function getListQuery()
{
    // Create a new query object.
    $db = $this->getDbo();
    $query = $db->getQuery(true);

    // Select the required fields from the table.
    $query->select(
        $this->getState(
            'list.select',
            'a.id, a.title, a.alias, a.title_alias, a.introtext, a.fulltext, ' .
            'a.checked_out, a.checked_out_time, ' .

The second way, and the Joomla! update proof way (& therefore probably the better way) is to load the entire article in the override (ugly but it's not a hack) and concatenate the fulltext to the introtext of the first article.

To do this you simply use getTable to load the article using the $this->item->id in blog.php for the first leading item, so at about line 54, between the <?php and the $this->item = &$item; put:

if($leadingcount == 0) {
    $contentTable = JTable::getInstance('Content');
    if($contentTable->load($item->id)) {
        $item->introtext .= $contentTable->fulltext;
    }
}

N.B. The if just limits it to the first leading article, if you remove the if it will attach the full text for all leading articles.

This works on my dev installation of Joomla! 2.5.6 so you should be able to do it as well.

OTHER TIPS

Considering the two answers above, there are three changes required to blog.php and blog_item.php. This works in Joomla 3.1 The best is to copy these files to the template override

copy blog.php and blog_item.php

from components/com_content/views/category/tmpl/

to [my template]/html/com_content/category/

In blog.php in the loop for the leading items add one single line:

  <?php foreach ($this->lead_items as &$item) : ?>
   <div class="leading-<?php echo ...?>">
                <?php
                    $this->item = &$item;
                    $this->item->leadingItem = true; //ADD THIS LINE !!!
                    echo $this->loadTemplate('item');
                ?>
            </div>
            <div class="clearfix"></div>
            <?php
               $leadingcount++;
            ?>
        <?php endforeach; ?>

In the blog_item.php replace "echo $this->item->introtext;" with

if ($this->item->leadingItem){
//this is a leading article - show full text and remove "Read more..." button
        $itemID =  $this->item->id;
        $db =& JFactory::getDBO();
        $query = "SELECT `fulltext` FROM `#__content` WHERE `id` =" . $itemID;
        $db->setQuery($query);
        $fulltext = $db->loadResult();
        echo $this->item->introtext . $fulltext; 

    }else{

        echo $this->item->introtext; 
}

Finally in the blog_item.php do not to show the "Read more..." button at the bottom of each article

Edit line

if ($params->get('show_readmore') && $this->item->readmore)

into

if ($params->get('show_readmore') && $this->item->readmore && !$this->item->leadingItem)

Joomla 2.5.x, in your template blog_item.php:

$itemID =  $this->item->id;
$db =& JFactory::getDBO();
$query = "
SELECT `fulltext` 
FROM `#__content` 
WHERE `id` = $itemID;
";
$db->setQuery($query);
$fulltext = $db->loadResult();

and you can use the $fulltext string variable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top