douyi2798 2014-06-30 06:32
浏览 67
已采纳

在Joomla中显示文章的动态列表

In a category list, I'd like to be able to display the list of articles dynamically. The website I'm developing allows a user to "submit" an article once they have read it. When they hit the submit button, the ID of that article is stored in the database in a table called "completed_quests." What I need to do is have Joomla check to see if the article ID exists in both the "content" and the "completed_quests" tables. If the article ID exists in both tables, then the article should not be displayed in the category list as that article or "quest" has already been submitted. If the article ID exists in the "content" table, but NOT in the "completed_quests" table, then the article SHOULD be displayed in the category list as it has note yet been submitted.

I'm wondering if there is a specific core Joomla file I should override to alter the category list output, or if I should develop a custom module to create this dynamic list. Any guidance would be much appreciated. If you have any other thoughts about how to display this dynamic list, I'm all ears.

edit: I've started by developing a custom module within Joomla, at least for testing. The below code is not working as expected. When I take out the following line "WHERE arp2i_completed_quests.id IS NULL" it displays a list of articles that exist in both tables. But what I need it to do is display the rows that exist in the content table but NOT in the completed_quests table. When I add the WHERE , it displays the text "ID:" and "TABLE:" for each row that exists, but the actual id and title from that row is not echo'ed to the screen. Please help.

Working code (see comments).

<?php

$query = "SELECT * FROM arp2i_completed_quests RIGHT JOIN arp2i_content ON arp2i_content.id=arp2i_completed_quests.id WHERE arp2i_completed_quests.id IS NULL LIMIT 0, 30 "; // prepare query

$db = &JFactory::getDBO(); // get database object
$db->setQuery($query); // apply query
$articles = $db->loadObjectList(); // execute query, return result list

foreach($articles as $article){ // loop through articles
    echo 'ID:' . $article->id . ' Title: ' . $article->title . '<br />';

} 

?>
  • 写回答

2条回答 默认 最新

  • dongqiang5865 2014-06-30 20:51
    关注

    You could override the com_content's listings view in your template.
    You do that by copying default.php from /components/com_content/views/categories/tmpl/ to /templates/yourtemplate/html/com_content/categories/

    However, I believe that such template overrides only allow you to update the display files of modules and components (the default.php files), and not the models, which would mean you have to add database queries into this layout file (or into a library), which feels a very hacky approach. It should work, though.

    A better solution would be to create a bespoke component with a single view, and a model that queries your database to create the appropriate listings. It may even make sense to just make the whole thing a bespoke component (saving the articles in that component) and not use Joomla's articles manager at all.

    If your listings page is not paginated, or if you do not care about an SEO friendly URL on secondary pages, then you also could create a module to display the listings and insert that into an article area. Modules are often simpler to make than components. You enter the database query into the helper file of a module.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?