【发布时间】:2012-12-13 13:16:08
【问题描述】:
显示类别(由 ID 指定)中的文章的代码是什么?
在 Wordpress 中,这样做相当容易:
<?php
query_posts('cat=1');
while (have_posts()) : the_post();
the_title();
endwhile;
?>
我正在为 Joomla 寻找类似的代码。
【问题讨论】:
显示类别(由 ID 指定)中的文章的代码是什么?
在 Wordpress 中,这样做相当容易:
<?php
query_posts('cat=1');
while (have_posts()) : the_post();
the_title();
endwhile;
?>
我正在为 Joomla 寻找类似的代码。
【问题讨论】:
在 joomla 中没有直接的代码可以像 word press 一样获得这个。
如果您想检查代码,您可以通过以下路径检查实现此目的的代码。
components/com_content/view/category/view.html.php
and
components/com_content/view/category/tmpl/blog.php
根据我的猜测,您的要求是显示同一类别的文章。
然后在 joomla 中你不需要编辑任何代码。 为此,您可以简单地创建一个菜单。 并且菜单布局类型应该是类别博客并从右侧类别选项中选择您的类别。
这将获得该类别的完整文章。
如果你想以你的风格管理它,你可以添加基于 blog.php 文件的风格。
希望对你有所帮助..
【讨论】:
$db = JFactory::getDbo();
$id = 50;//example
$query = $db->getQuery(true);
$query->select('*');
$query->from('#__content');
$query->where('catid="'.$id.'"');
$db->setQuery((string)$query);
$res = $db->loadObjectList();
foreach($res as $r){
echo '<h3>'.$r->title.'</h3>';
echo $r->introtext;
}
【讨论】:
您可以使用下一个代码模板:
$categoryId = $[category id];
require_once("components/com_content/models/category.php");
$category = new ContentModelCategory();
$category->hit($categoryId);
$articles = $category->getItems();
print_r($articles);
【讨论】:
试试这个:
$articles = JFactory::getDBO()->setQuery("SELECT * FROM #__content WHERE catid = '21'")->loadObjectList();
当然用你的类别的 id 替换 '21'。
【讨论】:
这在 Joomla 中很容易。您可以在 getItems()
下的 /components/com_content/models/category.php 中找到代码下面是一个例子
$model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
$model->setState('params', JFactory::getApplication()->getParams());
$model->setState('filter.category_id', $category_id);
$articles = $model->getItems();
【讨论】: