Detect Joomla section ID when viewing an article
Sometimes when you’re coding a Joomla 1.5 template you may want to be know which section an article is in. For example, let’s say you have designed custom navigation buttons (not using any Joomla module, just your own graphics). If you have a button called “About Us”, you’d want it to stay activated when viewing any page in the About Us part of the site. To do this, create a section called About Us, create a category within that, and put all About pages in there. Now you can reliably detect your articles’ section IDs as a way of keeping your button activated on the correct pages.
Add this in your template PHP code;
Now you can use if statements like this;
if($sectionid == ’4′){
echo “this article is in section 4!”;
}
You can use this for customized navigation, for example, keeping certain buttons highlighted when you’re viewing articles within a certain section. It can be used to display a module only if you’re in a certain section, but it’s useful for more than just modules. Enjoy.

July 26th, 2010 - 13:30
this doesn’t work. tried it, throws an error
July 26th, 2010 - 13:33
my mistake, it works, but you have to change the quotation marks. Yours came into my editor in a wierd way so retyping them fixed it.
July 26th, 2010 - 13:33
sorry. WordPress doesn’t make it easy to copy and paste the code
October 15th, 2010 - 00:54
This sounds great to utilise to my new joomla site. I’m a newbie anyway.
Stan, could you please let us know which quotation mark you used to make this script worked?
Cheers!
December 2nd, 2010 - 04:27
I have installed the 1.3.0 version of yvComment on Joomla 1.5 Beta2, and it is working okay in normal article views – I can write and view comments.
My doubt is if this also should work in a “Category Blog Layout”. When I use the blog layout, I see this under each article in the blog: This is comment of “”
If there is added any comments to the article in the normal view, I also see this in the blog layout: Comments (1)
However I cannot read the comment or link to it from the blog. I would also like to have the option to add comments directly from the blog.
Any ideas if this a only a local problem for me, or can someone give some hints if I need to modify something? (I am new to Joomla, so please explain in details)
December 2nd, 2010 - 09:52
why are you using a beta version of 1.5?
As for yvComment .. I have not used it. I use and like JomComment. Your question should be directed to yvComment support or their forum, I think.
Maybe some of our readers know the answer?
February 14th, 2011 - 18:38
This doesn’t work. My $sectionid is empty after running the script.
February 14th, 2011 - 18:44
it is probably a problem with the quotation marks in this post. Try this version instead; http://www.plethoradesign.com/detect-joomla-section-id-when-viewing-an-article
February 15th, 2011 - 13:08
Nope nothing (btw 2 errors on that page: two dots: .. and no ; at end) Please try to add
echo $sectionid; at the end, script shows nothing, so its empty. Is it important to put this code is head section, or something.
February 15th, 2011 - 20:11
OK try it now. Thanks for alerting me to the formatting error. I moved much of the blog over to the company site and in so doing noticed WordPress liked to add its own quotation marks in, which messed things up.
I updated this post with the corrected code – you can also see http://www.plethoradesign.com/detect-joomla-section-id-when-viewing-an-article .. it is easier to copy the code from there.
The code can go anywhere in the page … doesn’t have to be in the head. I use it to show certain menus on certain sections. Of course, with Joomla 1.6 this will be useless, since there are no sections in 1.6, only categories.