简体   繁体   English

PHP代码在Joomla特色博客视图菜单项中显示文章标题

[英]PHP Code to display article title in Joomla Featured Blog View Menu Item

I am currently developing a Joomla 1.7 website, And I am using J2Store shopping Cart so I have to make make an article for every Product. 我目前正在开发Joomla 1.7网站,并且正在使用J2Store购物车,因此我必须为每个产品制作一篇文章。

Then to display I create a Joomla Featured Articles Menu Item for the appropriate Category, my problem is this, The default Article Title isn't really appropriate for the page layout and because there will be many products / articles so as a time saver I would like to include some PHP code to retrieve the Article Title I have tried the following used in conjunction with the Sourcerer plugin. 然后显示,我为适当的类别创建了一个Joomla特色文章菜单项,我的问题是,默认的文章标题实际上并不适合页面布局,因为会有很多产品/文章,这样可以节省时间想要包含一些PHP代码来检索文章标题,我尝试将以下代码与Sourcerer插件结合使用。

<?php echo JFactory::getDocument()->getTitle(); ?>

But unfortunately it displays the Menu Title not the individual Article Titles, I also found the following code but I cant get it to work with Joomla 1.7 但是不幸的是,它显示菜单标题而不是单个文章标题,我还找到了以下代码,但无法与Joomla 1.7一起使用

<?php   
    $option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');
if ($option=="com_content" && $view=="article") {
    $ids = explode(':',JRequest::getString('id'));
    $article_id = $ids[0];
    $article =& JTable::getInstance("content");
    $article->load($article_id);
    echo $article->get("title");
} ?>

Try this: 尝试这个:

$product =& JTable::getInstance("content");
$product->load($product_id);
echo $product->get("title");

And replace $product_id with whatever ID needed. 并用所需的ID替换$product_id

Look at this file: 看一下这个文件:

components/com_content/views/featured/tmpl/default.php 组件/com_content/views/featured/tmpl/default.php

That's the original template for the Featured Articles view, you can override it as explained in this link: 这是“特色文章”视图的原始模板,您可以按照此链接中的说明进行覆盖:

http://docs.joomla.org/How_to_override_the_output_from_the_Joomla!_core http://docs.joomla.org/How_to_override_the_output_from_the_Joomla!_core

to include a piece of code like this (in the file you created on your template folder): 包括这样的一段代码(在您在模板文件夹中创建的文件中):

<?php 
foreach($this->items as $fItem): 
    echo $fItem->title.'<br/>';
endforeach;
?>

Voilà, you will see all the titles from the displayed featured articles. Voilà,您将看到显示的特色文章的所有标题。

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

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