Joomla!-开源天空

2008-12-05
首页 专栏热点 Joomla! 源代码分析 中文自动标签生成Joomla!扩展制作教程(五)-增加组件列表功能


中文自动标签生成Joomla!扩展制作教程(五)-增加组件列表功能

E-mail

在上一篇文章中,我们利用插件显示了文章的标签,但是标签的链接指向,比如:http://www.maycode.com/index.php?option=com_tags&view=list&key=%E6%A8%A1%E6%9D%BF

显然我们需要给com_tags组件添加list视图,这很容易,在com_tags的views目录下,创建一个list目录,在目录中增加list.php和tmpl/default.php。

代码分别如下:

<?php
/**
 * Module Generator Component
 *
 * @package    Maycode.Tool
 * @subpackage Components
 * @link http://www.maycode.com/
 * @license  GNU/GPL
 */
jimport( 'joomla.application.component.view');
jimport('joomla.html.pagebar');
class TagsViewList extends JView
{
 function display($tpl = null)
 {
  global $mainframe;  
  $db = & JFactory::getDBO();
  $lang = & JFactory :: getLanguage();
    $lang->load('com_Tags');  
  $params = &$mainframe->getParams();
  $searchword = JRequest::getVar('key');
   $limitstart = JRequest::getVar('start', 0, '', 'int');
   $limit =10;
  $pagination = null; 
  JRequest::setVar('limit', (int) $limit); 
  $items = array();
    if(! empty($searchword)) {
    $searchword = urldecode($searchword);
    $query = 'select count(*) from #__tags where tag="'.$searchword.'"';
    $db->setQuery($query);
    $total = $db->loadResult();
    
    $query = 'select * from #__tags where tag="'.$searchword.'" limit '.$limitstart.','.$limit;
    $db->setQuery($query);
    $rows = $db->loadObjectList();  
        $pagination = new JPagebar($total, $limitstart, $limit);
    $i = 0;
        foreach ($rows as $row) {
         $query = 'select * from #__content where id='.$row->articleid;
         $db->setQuery($query);
     $articlerow = $db->loadObject();
     $items[$i]['title'] = $articlerow->title;
     $items[$i]['content'] = JString::substr(htmlentities(strip_tags($articlerow->introtext),ENT_NOQUOTES,'UTF-8'),0,100);
     $items[$i]['url'] = $row->url;
     $i++;
        }       
    } 
    $this->assignRef('items',$items); 
    $this->assign('searchword',$searchword); 
    $this->assignRef('params',$params);
    $this->assignRef('pagination',$pagination); 
  parent::display($tpl);
 }
 function &getItem($index = 0)
 {
  $item =& $this->items[$index];
  return $item;
 }
}
?>

模板文件tmpl/default.php代码:

<?php 
// no direct access
defined('_JEXEC') or die('Restricted access');
?>
<table class="contentpaneopen<?php echo $this->params->get( 'pageclass_sfx' ); ?>">
 <tr>
  <td>
  <?php
   for ($i=0;$i<count( $this->items ); $i++) {
   $item = $this->items[$i];
  ?>
   <fieldset>
    <div>
     <span class="small<?php echo $this->params->get( 'pageclass_sfx' ); ?>">
      <?php //echo $this->pagination->limitstart + $result->count.'. ';?>
     </span>   
       <a href="/<?php echo $item['url'];?>" target="_blank">
        <?php echo $item['title'];?>
       </a>
    </div>
    <div>
     <?php echo $item['content']; ?>
    </div>
   </fieldset>
  <?php } ?>
  </td>
 </tr>
 <tr>
  <td colspan="3">
   <div align="center">
    <?php if($this->pagination) echo $this->pagination->getPagesLinks( ); ?>
   </div>
  </td>
 </tr>
</table>
 

下载附件的代码,试试吧。效果如下:

Attatchments:
您还没有登录,登录后方能下载,如果您还没有注册,请点击 免费注册
相关文章:
中文tags cloud Joomla! 组件发布
中文自动标签生成Joomla!扩展制作教程(九)-tags cloud 模块完整版
中文自动标签生成Joomla!扩展制作教程(八)-tags cloud 模块
简体中文标签自动生成Joomla!组件,插件,标签云模块
中文自动标签生成Joomla!扩展制作教程(七)-com_tags管理后台分页
中文自动标签生成Joomla!扩展制作教程(六)-自动生成文章标签
中文自动标签生成Joomla!扩展制作教程(四)-创建插件
中文自动标签生成Joomla!扩展制作教程(三)-增加组件的tags生产功能
中文自动标签生成Joomla!扩展制作教程(二)-创建组件框架
中文自动标签生成Joomla!扩展制作教程(一)-前言


收藏此文章:
Digg! Reddit! Del.icio.us! JoomlaVote! Google! Live! Facebook! StumbleUpon! Yahoo! Free social bookmarking plugins and extensions for Joomla! websites!

发表您的文章评论

您的姓名 (昵称)
标题:
评分: 很差一般较好很好
评论:
验证码:
请输入验证码