简体   繁体   English

Joomla,如何在模块最新中显示类别名称

[英]Joomla, how to display category name in module latest

I've been trying to display the category name after the contents of the 'Latest' module in Joomla. 我一直在尝试在Joomla中“最新”模块的内容之后显示类别名称。

I've made the query in phpMyAdmin and it works. 我已经在phpMyAdmin中进行了查询,并且可以正常工作。 But when I try to use this in the php module template page the page stops at the point the php should start. 但是,当我尝试在php模块模板页面中使用此页面时,该页面会停止在php应该开始的位置。

$db = &JFactory::getDBO(); 
$id = JRequest::getString('id'); 
$db->setQuery("SELECT `title` FROM `#__categories` WHERE `id` = " .$item->catid); 
$category = $db->loadResult();
echo $category;

When I replace $item->catid with a fixed number, it works like it does in phpMyAdmin. 当我用固定数字替换$ item-> catid时,它的工作原理与phpMyAdmin中的一样。 Can anyone tell me where I go wrong? 谁能告诉我我哪里出问题了?

Thanks 谢谢

$item is already having the category title so no need to get it through a db query. $ item已经具有类别标题,因此无需通过数据库查询获取它。 You can simply do this in your tmpl file. 您可以简单地在tmpl文件中执行此操作。 You can get the category using $item->category_title 您可以使用$item->category_title获得$item->category_title

<ul class="latestnews<?php echo $moduleclass_sfx; ?>">
<?php foreach ($list as $item) :  ?>
    <li itemscope itemtype="http://schema.org/Article">
        <a href="<?php echo $item->link; ?>" itemprop="url">
            <span itemprop="name">
                <?php echo $item->title; ?>-
                <b><?php echo $item->category_title; ?></b>
            </span>
        </a>
    </li>
<?php endforeach; ?>
</ul>

UPDATE: if you want to display as you asked in comments then you need to do this 更新:如果要按注释中的要求显示,则需要执行此操作

<ul class="latestnews<?php echo $moduleclass_sfx; ?>">
<?php foreach ($list as $item) :  ?>
    <li itemscope itemtype="http://schema.org/Article">
        <a href="<?php echo $item->link; ?>" itemprop="url">
            <span itemprop="name">
                <?php echo $item->title; ?>       
            </span>
        </a>
    </li>
<?php endforeach; ?>
<b><a href="<?php JRoute::_("index.php?option=com_content&view=category&layout=$item->category_title&id=$item->catid"); ?>">Click here for more news on ("<?php echo $item->category_title; ?>")</a></b>
</ul>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM