用于查看文章标题和文章中的一张图像的简单模块,
我需要创建简单的模块来查看文章标题和文章中的一张图像,问题是我不知道如何从文章中获取一张图像。
这是我的代码:
<?php
defined('_JEXEC') or die('Restricted access');
$db =& JFactory::getDBO();
$query = "
SELECT ".$db->nameQuote('images')." ,".$db->nameQuote('title')."
FROM ".$db->nameQuote('#__content').";
";
$db->setQuery($query);
$rows = $db->loadObjectList();
foreach ($rows as $row)
{
//echo "<p>The article text of '$row->fulltext' is $row->id </p>\n";
echo "<p>The article image of '$row->images' </p>\n";
echo "<p>The article title of '$row->title' </p>\n";
}
?>
I need to created simple module to view article title and one image from the article, The problem is I have no idea how to get one image from the article.
This is my code:
<?php
defined('_JEXEC') or die('Restricted access');
$db =& JFactory::getDBO();
$query = "
SELECT ".$db->nameQuote('images')." ,".$db->nameQuote('title')."
FROM ".$db->nameQuote('#__content').";
";
$db->setQuery($query);
$rows = $db->loadObjectList();
foreach ($rows as $row)
{
//echo "<p>The article text of '$row->fulltext' is $row->id </p>\n";
echo "<p>The article image of '$row->images' </p>\n";
echo "<p>The article title of '$row->title' </p>\n";
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
标准 Joomla 文章没有用于存储图像日期的字段。图像直接插入到内文或全文字段中。为此,您需要使用正则表达式来查找图像的第一个实例。
另一种选择是安装众多 CCK 类型扩展之一,这些扩展允许您定义内容类型或向 Joomla 文章添加额外字段。 K2 所做的正是您在默认安装中尝试做的事情,包括显示标题和图像的模块。
Standard Joomla articles do not have a field for storing image date. Images are inserted directly in to the introtext or fulltext fields. You would need to use a regular expression to find the first instance of an image in order to do this.
The other option is to install one of many CCK type extensions that allow you to define content types or add extra fields to the Joomla article. K2 does exactly what you are trying to do with the default installation including the module to display the title and image.