0

I want to display the com_tags tag title in a module while on the "Tagged Items" menu item page.

My goal is for this code to display the title for the current tag. For example, when on this page: /index.php?option=com_tags&view=tag&id=20, the tag title for id=20 should be displayed.

I found this code but I don't understand the WHERE code.

$db = JFactory::getDbo();
$query = $db->getQuery(true);

$db = JFactory::getDbo();
$query = $db->getQuery(true)
    ->select('title')  
    ->from($db->quoteName('lfco8__tags'))
    ->where($db->qn('id') . " = " . $_GET['id'])
    ;
$db->setQuery($query);
$result = $db->loadResult();
print_r($result);

Please reply with different code if there is something better like some json code or other.

13
  • The WHERE code is a filter saying only return records that match the id of the tag you want to retrieve, in this case $item->id. If the tag you want to retrieve is called Fred and has an id of 505 then the WHERE clause would look like WHERE `id` = '505' or WHERE `id` = $item->id, where $item->id equals 505. The $db->qn() & $db->q() are Joomla functions that make sure the values each side of the operator are correctly wrapped in quotes. They are not required, but good practice to include them. Without a WHERE clause you would get all records returned in the result.
    – Irata
    Commented Oct 22, 2021 at 4:24
  • My goal is for this code to display the title for the current tag. For example, when on this page: /index.php?option=com_tags&view=tag&id=20, the tag title for id=20 should be displayed. Commented Oct 22, 2021 at 6:42
  • Where is this code placed exactly?
    – Sharky
    Commented Oct 22, 2021 at 6:53
  • I see a typo in ->>where <-- too many >'s. Commented Oct 22, 2021 at 7:35
  • @Sharky The code is in a custom_html module using Regular Labs Sourcerer. Commented Oct 22, 2021 at 8:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.