How to get current category title (joomla position)

More
10 years 1 month ago #45275 by szallontai
Hello,

I search a way to add category title off current page in joomla template position.
Code:
<h1><?php $doc =& JFactory::getDocument(); echo '' . $doc->getTitle(); ?></h1>
working but in item view you get CatTitle - Itemtitle

Is there an efficient way by flexicontent router ?
without requeting database in template files.

thanks for your help

Please Log in or Create an account to join the conversation.

More
10 years 1 month ago #45313 by ggppdk
Hello

item has multiple categories, you mean you want title of main category?

there is a cached always available array with category data
Code:
global $globalcats; echo $globalcats[$item->catid]->title;

to see what is available do:
Code:
echo "<pre>" . print_r($globalcats[$item->catid], true) . "</pre>";

Regards


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...
The following user(s) said Thank You: iamrobert

Please Log in or Create an account to join the conversation.

More
10 years 1 month ago #45360 by szallontai
Hi,

thank you for your concern
Yes of course I mean display current main category title.

I put your print_r code, but I have no result
in the source code I just html tag <pre> </pre> empty.

Any avaible in cache for category data !!!
I pay attention to enable caching in template and joomla config. I'm in J3.2

I'm confuse :P
Best regards

Please Log in or Create an account to join the conversation.

More
10 years 1 month ago #45361 by ggppdk
Hello

$item->catid is an example use what is available in your case:

e.g.
$row->catid

e.g.
$main_catid

before executing any code also add this to temporarily enable error_reporting and see if a variable exists:
error_reporting(E_ALL & ~E_STRICT);
ini_set('display_errors',1);


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

More
10 years 1 month ago #45892 by szallontai
I'm sorry but i'm lost !!

to get CatTitle, in template :
Code:
<?php $db = &JFactory::getDBO(); $option = JRequest::getCmd('option'); $view = JRequest::getVar('view', '', 'REQUEST', 'ALNUM'); if ($option == 'com_content' && ($view == 'item' || $view =='category') ) { $id = JRequest::getString('id'); //si article if ($view == 'item') { $query = "SELECT catid FROM #__content WHERE id = ".$id ; $db->setQuery($query); //dump($db); $masectionid = $db->loadResult(); } //si category else { $query = "SELECT id FROM #__categories WHERE id = ".$id; $db->setQuery($query); //dump($db); $masectionid = $db->loadResult(); } $query = "SELECT title FROM #__categories WHERE id = ".$masectionid ; $db->setQuery($query); //dump($db); $sectiontitre= $db->loadResult(); } echo $sectiontitre; ?>

I test sql requeting in phpmy admin and have good response. But displaying empty at front !!

It seems pb is to get ID current view ?? :roll:

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.314 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline