Detecing which page we are in from the template

For Joomla! 1.0 Coding related discussions.
Locked
User avatar
rsd
Joomla! Apprentice
Joomla! Apprentice
Posts: 27
Joined: Mon Jun 26, 2006 6:21 pm
Contact:

Detecing which page we are in from the template

Post by rsd » Wed Apr 11, 2007 2:57 am

Hi,

I had posted it in the wrong section before.

I would like to findout from a template/frontend which page is being displayed.
It could be the menu item id or the page title.

Any pointers on how to accomplish this are very welcome, like the related API to use.

-rsd

User avatar
jlleblanc
Joomla! Guru
Joomla! Guru
Posts: 963
Joined: Fri Aug 19, 2005 12:37 am
Location: Washington, DC / NoVA
Contact:

Re: Detecing which page we are in from the template

Post by jlleblanc » Wed Apr 11, 2007 12:48 pm

If you want the current menu item number, you can find it stored in $Itemid. For the current page title, try calling $mainframe->getPageTitle().
Joseph L. LeBlanc: http://www.jlleblanc.com
Frontend components start here: /components/com_[name]/[name].php
Backend components start here: /administrator/components/com_[name]/admin.[name].php

User avatar
rsd
Joomla! Apprentice
Joomla! Apprentice
Posts: 27
Joined: Mon Jun 26, 2006 6:21 pm
Contact:

Re: Detecing which page we are in from the template

Post by rsd » Wed Apr 11, 2007 1:36 pm

Great!!
Exactly what I needed.

Thank you

User avatar
rsd
Joomla! Apprentice
Joomla! Apprentice
Posts: 27
Joined: Mon Jun 26, 2006 6:21 pm
Contact:

Re: Detecing which page we are in from the template

Post by rsd » Thu Apr 12, 2007 1:06 pm

jlleblanc wrote: If you want the current menu item number, you can find it stored in $Itemid. For the current page title, try calling $mainframe->getPageTitle().
Interesting that $Itemid solves my problem, getPageTitle returns the html page title (which I think is determined by the component), and not the menu "Page Title" option which is different.

Tried to inspect includes/joomla.php, but couldnt find a method to get the "Page Title" from the menu option.  Any lights on this.

Thanks.

User avatar
ianmac
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 4784
Joined: Sat Sep 24, 2005 11:01 pm
Location: Toronto, Canada

Re: Detecing which page we are in from the template

Post by ianmac » Thu Apr 12, 2007 6:50 pm

global $database;

$menu =& new mosMenu( $database );
$menu->load( $itemId );
echo $menu->name;

Ian

User avatar
rsd
Joomla! Apprentice
Joomla! Apprentice
Posts: 27
Joined: Mon Jun 26, 2006 6:21 pm
Contact:

Re: Detecing which page we are in from the template

Post by rsd » Fri Apr 13, 2007 1:57 pm

Great!! That solved it.

Thanks

-rsd

User avatar
gwmbox
Joomla! Explorer
Joomla! Explorer
Posts: 429
Joined: Thu Nov 10, 2005 8:05 am
Location: Western Australia
Contact:

Re: Detecing which page we are in from the template

Post by gwmbox » Tue May 15, 2007 2:35 pm

Hi guys, directed to your post, trying to work out how I can get the title of the page to show up in text, i.e. if I have a content item with a title called sometitle, I want to place that text (sometitle) in the content (using mossnippet to help me do that).  so by adding 'whatever' code will show me the title of the page.  I'm using it to append other text that is used in linking like content by way of using the simply links component

I've tried various ways based on your code above but my poor php skills are showing :(

Any chance you can advise what the correct php code is for me to pull up the content title for the specific content item being viewed?
If you don't ask....
Help yourself, use Firebug with Firefox

User avatar
gwmbox
Joomla! Explorer
Joomla! Explorer
Posts: 429
Joined: Thu Nov 10, 2005 8:05 am
Location: Western Australia
Contact:

Re: Detecing which page we are in from the template

Post by gwmbox » Wed May 16, 2007 12:15 am

Found it :)

Code: Select all

<?php
global $mainframe;
$fulltitle = $mainframe->_head['title'];
$sitename = $GLOBALS['mosConfig_sitename'] . ' - ';
$pagetitle = str_replace($sitename, '', $fulltitle);
echo $pagetitle;
?>
Yipee :)
If you don't ask....
Help yourself, use Firebug with Firefox

User avatar
eskwire
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 118
Joined: Sun Sep 25, 2005 3:57 pm
Location: Atlanta, GA
Contact:

Re: Detecing which page we are in from the template

Post by eskwire » Thu May 17, 2007 4:45 pm

This thread has been very helpful.  What variable would I call if I wanted to print the "title alias" from a static content page?

Thanks again for the help!

User avatar
jlleblanc
Joomla! Guru
Joomla! Guru
Posts: 963
Joined: Fri Aug 19, 2005 12:37 am
Location: Washington, DC / NoVA
Contact:

Re: Detecing which page we are in from the template

Post by jlleblanc » Thu May 17, 2007 4:57 pm

You would need to load the content item from the database to get that information. This code should do it:

Code: Select all

global $database;

$id = mosGetParam($_REQUEST, 'id', 0);

$row = new mosContent($database);
$row->load($id);

echo $row->title_alias;
Joseph L. LeBlanc: http://www.jlleblanc.com
Frontend components start here: /components/com_[name]/[name].php
Backend components start here: /administrator/components/com_[name]/admin.[name].php

User avatar
eskwire
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 118
Joined: Sun Sep 25, 2005 3:57 pm
Location: Atlanta, GA
Contact:

Re: Detecing which page we are in from the template

Post by eskwire » Thu May 17, 2007 5:15 pm

Worked like a charm!  Thanks

My next step is to select the background image based upon the value that is entered into the title alias.

I am new to php so I have some more research to.  Any tips on how to do this? 

I have started a thread in the Template and CSS forum:
http://forum.joomla.org/index.php/topic ... .html&nbsp;

I am excited to be making some progress!

Thanks Again

User avatar
eskwire
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 118
Joined: Sun Sep 25, 2005 3:57 pm
Location: Atlanta, GA
Contact:

Re: Detecing which page we are in from the template

Post by eskwire » Thu May 17, 2007 9:54 pm

Hi jlleblanc,

Thank you very much for your help.  Like I said my php and joomla dev skills are not the strongest right now.  Where could I go to start to learn more about the variables and what the code that you provided me is doing line by line?  I have put a write up of what i have done:  http://www.drretarded.com/websites/joom ... .html&nbsp; I would love to be able to provide further explanation for myself and others.

Any input you have is greatly appreciated!

User avatar
jlleblanc
Joomla! Guru
Joomla! Guru
Posts: 963
Joined: Fri Aug 19, 2005 12:37 am
Location: Washington, DC / NoVA
Contact:

Re: Detecing which page we are in from the template

Post by jlleblanc » Thu May 17, 2007 11:39 pm

Here's a set of tutorials you can reference: http://forum.joomla.org/index.php/topic,63383.0.html
Joseph L. LeBlanc: http://www.jlleblanc.com
Frontend components start here: /components/com_[name]/[name].php
Backend components start here: /administrator/components/com_[name]/admin.[name].php

User avatar
yustar2000
Joomla! Intern
Joomla! Intern
Posts: 51
Joined: Fri May 12, 2006 2:16 am
Location: China
Contact:

Re: Detecing which page we are in from the template

Post by yustar2000 » Fri May 18, 2007 12:53 am

thanks


Locked

Return to “Joomla! 1.0 Coding”