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 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)