Actions

J2.5

Difference between revisions of "Add article title to read more link"

From Joomla! Documentation

m (Reverted edits by Hei89 (talk) to last revision by Wilsonge)
Line 1: Line 1:
 
{{review}}
 
{{review}}
My name is Add article title to read more link and if you want to get in touch with me, post on my '''[[User_talk:{{PAGENAME}}|talk page]]'''.
 
 
==My testing subpages==
 
<splist/>
 
 
一些人想要把readmore链接增加到文章标题上,为了实现这个你可以使用
 
[[How_to_override_the_output_from_the_Joomla!_core|template override]].
 
如果没有找到,在你template文件夹:
 
#创建一个新的文件夹‘html’。
 
#在文件夹里面创建一个文件夹‘com_content’。
 
#在文件夹里面你分别创建文件夹‘category’、‘frontpage’、‘article’。
 
然后按照以下路径找到下列文件
 
*(joomla)/components/com_content/views/category/tmpl/blog_item.php
 
*(joomla)/components/com_content/views/featured/tmpl/default_item.php
 
*(joomla)/components/com_content/views/article/tmpl/default.php
 
然后复制粘贴到刚才创建的相应的文件夹内
 
*(yourtemplate)/html/com_content/category/blog_item.php
 
*(yourtemplate)/html/com_content/featured/default_item.php
 
*(yourtemplate)/html/com_content/article/default.php
 
打开文件,在每一个文件的底部你会找到如下的代码:
 
<source lang='php'>
 
<p class="readmore"><a class="btn" href="<?php echo $link; ?>"> <span class="icon-chevron-right"></span>
 
<?php if (!$params->get('access-view')) :
 
echo JText::_('COM_CONTENT_REGISTER_TO_READ_MORE');
 
elseif ($readmore = $this->item->alternative_readmore) :
 
echo $readmore;
 
if ($params->get('show_readmore_title', 0) != 0) :
 
echo JHtml::_('string.truncate', ($this->item->title), $params->get('readmore_limit'));
 
endif;
 
elseif ($params->get('show_readmore_title', 0) == 0) :
 
echo JText::sprintf('COM_CONTENT_READ_MORE_TITLE');
 
else :
 
echo JText::_('COM_CONTENT_READ_MORE');
 
echo JHtml::_('string.truncate', ($this->item->title), $params->get('readmore_limit'));
 
endif; ?>
 
</a></p>
 
</source>
 
这一行<source lang='php'>echo JText::sprintf('COM_CONTENT_READ_MORE_TITLE');</source>
 
改成<source lang='php'>echo JText::sprintf('COM_CONTENT_READ_MORE_TITLE', $this->item->title);</source>
 
这样那个'read more'链接就会如下所示
 
'''Read more: (Article title)'''
 
< translate over>
 
 
  
 
Some people want to add the article title to the readmore link. To achieve this you can use a [[How_to_override_the_output_from_the_Joomla!_core|template override]].
 
Some people want to add the article title to the readmore link. To achieve this you can use a [[How_to_override_the_output_from_the_Joomla!_core|template override]].

Revision as of 03:34, 29 March 2014

Copyedit.png
This Page Needs Your Help

This page is tagged because it NEEDS REVIEW. You can help the Joomla! Documentation Wiki by contributing to it.
More pages that need help similar to this one are here. NOTE-If you feel the need is satistified, please remove this notice.


Some people want to add the article title to the readmore link. To achieve this you can use a template override.

If they are not already there, in your template folder:

  1. Create a new folder called 'html'.
  2. In that folder you create a folder called 'com_content'.
  3. And in that folder you create the folders called "category", "frontpage" and "article"

Then locate the following files:

  • (joomla)/components/com_content/views/category/tmpl/blog_item.php
  • (joomla)/components/com_content/views/featured/tmpl/default_item.php
  • (joomla)/components/com_content/views/article/tmpl/default.php

Copy the files to their respective locations in the template's html file:

  • (yourtemplate)/html/com_content/category/blog_item.php
  • (yourtemplate)/html/com_content/featured/default_item.php
  • (yourtemplate)/html/com_content/article/default.php

Open these files. Towards the bottom of each of these files you should see something like:

<p class="readmore"><a class="btn" href="<?php echo $link; ?>"> <span class="icon-chevron-right"></span>
        <?php if (!$params->get('access-view')) :
                echo JText::_('COM_CONTENT_REGISTER_TO_READ_MORE');
        elseif ($readmore = $this->item->alternative_readmore) :
                echo $readmore;
                if ($params->get('show_readmore_title', 0) != 0) :
                echo JHtml::_('string.truncate', ($this->item->title), $params->get('readmore_limit'));
                endif;
        elseif ($params->get('show_readmore_title', 0) == 0) :
                echo JText::sprintf('COM_CONTENT_READ_MORE_TITLE');
        else :
                echo JText::_('COM_CONTENT_READ_MORE');
                echo JHtml::_('string.truncate', ($this->item->title), $params->get('readmore_limit'));
        endif; ?>
</a></p>

Change the line

echo JText::sprintf('COM_CONTENT_READ_MORE_TITLE');

into

echo JText::sprintf('COM_CONTENT_READ_MORE_TITLE', $this->item->title);

The “Read more” link should now look like this: Read more: (Article title)