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.
id
of the tag you want to retrieve, in this case$item->id
. If the tag you want to retrieve is calledFred
and has anid
of505
then the WHERE clause would look likeWHERE `id` = '505'
orWHERE `id` = $item->id
, where$item->id
equals505
. 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./index.php?option=com_tags&view=tag&id=20
, the tag title forid=20
should be displayed.->>where
<-- too many>
's.