PHP conditional based on page/section other than 'frontpage'

Have a programming question regarding your component, plug-in, extension or core hacks? Have an interesting tidbit, FAQ or programming tip you’d like to share? This is the place for you.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Post Reply
lexpresso
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Thu May 31, 2007 11:20 pm

PHP conditional based on page/section other than 'frontpage'

Post by lexpresso » Thu Oct 25, 2007 11:13 pm

I've figured out how to create conditional for content to appear based on whether the user is on the 'frontpage' or not, but how do you do it for any other page.

For example:

I want my 'main content' component to appear in one div on the frontpage, yet on another when I click on the "articles" link.  This in order to achieve different widths for each.  Are the names of the other "pages" custom...in otherwords can refer to them with the section name?

:pop

Opie
Joomla! Apprentice
Joomla! Apprentice
Posts: 47
Joined: Thu Jun 22, 2006 7:32 pm
Contact:

Re: PHP conditional based on page/section other than 'frontpage'

Post by Opie » Fri Oct 26, 2007 3:13 am

You could use two separate templates.

Also, if you know if the visitor is on the front page, can you not reverse that check to determine when you are not on the front page?
http://springhillalumni.org • Springhill High School Alumni Association

lexpresso
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Thu May 31, 2007 11:20 pm

Re: PHP conditional based on page/section other than 'frontpage'

Post by lexpresso » Fri Oct 26, 2007 3:18 am

Yes I can, but I can't distinguish between various secondary pages:

Example:

if page==blog...or could be if section==blog {show this}

Is that clearer? :pop

User avatar
AmyStephen
Joomla! Guru
Joomla! Guru
Posts: 579
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: PHP conditional based on page/section other than 'frontpage'

Post by AmyStephen » Sat Oct 27, 2007 3:10 am

You can look at the global variable $Itemid, a value associated with the menu item (it can be seen on the menu item line.)

Typically, it's a good idea to layout your menu item pages in a grid, then consider where all of your modules and component will go. Frequently, that knowledge is all that is needed to conditionally hide or show modules in the template.

Rarely do template designers create an entire template page for each menu item. But, if you do, then you should consider using the Template Manager to assign your various looks to the menu items. That way, you can keep the index.php files simpler.

Hope that helps!
Amy :)
~*~ Joomla!'s Queen of the Blues - Jennifer Marriott ~*~
http://OpenSourceCommunity.org/node/1719/

lexpresso
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Thu May 31, 2007 11:20 pm

Re: PHP conditional based on page/section other than 'frontpage'

Post by lexpresso » Sat Oct 27, 2007 5:10 am

Thanks.  That should work. 

Can you also refer to the id on in php conditional just as much as you can refer to the view?
Last edited by lexpresso on Sun Oct 28, 2007 2:38 am, edited 1 time in total.

User avatar
AmyStephen
Joomla! Guru
Joomla! Guru
Posts: 579
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: PHP conditional based on page/section other than 'frontpage'

Post by AmyStephen » Sat Oct 27, 2007 7:38 pm

lexpresso wrote:Can you also refer to the id on in php conditional just as much as you can refer to the view?


Yes, you certainly can! Here's an example:

Code: Select all

<?php If ($Itemid == 23) { ?>
do something
<?php } ?>


Good luck with your work,
Amy :)
~*~ Joomla!'s Queen of the Blues - Jennifer Marriott ~*~
http://OpenSourceCommunity.org/node/1719/


Post Reply