How to get current category title (joomla position)

4 years 2 months ago #45275 by szallontai
Hello,

I search a way to add category title off current page in joomla template position.
<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.

4 years 2 months 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
global $globalcats;
echo $globalcats[$item->catid]->title;

to see what is available do:
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 review. Thanks!
The following user(s) said Thank You: iamrobert

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

4 years 2 months 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.

4 years 2 months 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 review. Thanks!

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

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

to get CatTitle, in template :
<?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
© 2018 Flexicontent. All Rights Reserved.