简体   繁体   中英

Display Dynamic List of Articles in 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 />';

} 

?>

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.

You should just develop a content view that does exactly what you want. Should be very simple if you have some programming experience. You needn't change any core files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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