简体   繁体   English

如何获取Joomla文章的标题?

[英]How to fetch the title of a Joomla article?

I have designed a Joomla template. 我设计了一个Joomla模板。 I want to bring my articles on my template, I have written code that is bring article body text on my template but neither image nor title is coming up. 我想将我的文章带到模板上,我编写了代码,将文章正文文本带到了模板上,但是图像和标题都没有出现。 Can anyone help please ? 有人可以帮忙吗?

$query = "select * from jh7na_content order by id desc limit 2";
$sql = mysql_query($query) or die(mysql_error());
while($row=mysql_fetch_array($sql)){
    echo "<div id='div1' style='border='2px';'>".html_entity_decode($row['introtext'])."</div>";             
}

A few things you should know. 您应该知道的几件事。 Firstly, if you want to show an article, why not create a menu item, and assign an article to it in the Joomla backend? 首先,如果要显示文章,为什么不创建菜单项,并在Joomla后端为其分配文章? Secondly, your query is only showing the article text because you have told it to and are not calling the Title. 其次,您的查询仅显示文章文本,因为您已经告诉过文章并且没有调用标题。 Thirdly, you should be using Joomla coding standards, especially when making database queries, like so: 第三,您应该使用Joomla编码标准,尤其是在进行数据库查询时,例如:

$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('*')
 ->from('#__content')
 ->order('id DESC');
$db->setQuery($query,0,2);
$rows = $db->loadObjectList();

foreach($rows as $row){
    echo "<div class='title'>" . $row['title']. "</div>"; 
    echo "<div class='introtext'>" . $row['introtext']. "</div>"; 
}

However, as stated before, you should assign an article to a menu item. 但是,如前所述,您应该将文章分配给菜单项。

Hope this helps 希望这可以帮助

Well since you are only echoing the intro text and not the title or the image, that would explain why the introtext and not the title or image is showing. 好吧,因为您仅回显介绍文字,而不回显标题或图像,所以这可以解释为什么显示介绍文字而不是标题或图像。 Look at the core layouts to see how to render each part of an article. 查看核心布局,以了解如何呈现文章的每个部分。

However, if you mean you have written an actual template, which in Joomla is used for design purposes, you should not be putting any specific code like this there, you would just be using a jdoc statement to include your article. 但是,如果您是说已经编写了一个实际的模板,该模板在Joomla中用于设计目的,则不应在其中放置任何特定的代码,而只是使用jdoc语句来包含您的文章。

Do not reinvent the wheel. 不要重新发明轮子。 Joomla is a content management system, use it for content management. Joomla是一个内容管理系统,用于内容管理。 It will automatically load your content for you. 它将自动为您加载内容。 That's what it is totally designed to do -- take care of that part while you worry about content and design. 这就是它完全旨在做的事情-在担心内容和设计的同时要照顾好那部分。 If you want to make a different appearing page than the core you can do a layout override (search for an answer on how to do that). 如果您要制作一个与核心页面不同的页面,则可以进行布局覆盖(搜索有关此操作的答案)。 But I suggest first that you learn a bit about how Joomla works. 但我建议您首先了解一下Joomla的工作原理。 Open up the core code and study it, then you will know how to work with it. 打开核心代码并进行研究,您将知道如何使用它。

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

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