Page Class Suffix in template code

Everything to do with Joomla! 1.5 templates and templating.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
ralphonz
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Mon Oct 20, 2008 3:58 pm

Re: Page Class Suffix in template code

Post by ralphonz » Tue Oct 21, 2008 9:03 pm

its http://www.sonic-rites.com

i want a different style to show on the artist content items

Thanks for taking the time to look

User avatar
mark_up
Joomla! Guru
Joomla! Guru
Posts: 849
Joined: Sun Oct 29, 2006 10:51 am
Location: Fiji
Contact:

Re: Page Class Suffix in template code

Post by mark_up » Tue Oct 21, 2008 9:18 pm

Hmmm... Replicant is a little complicated.

Parts of the style are controlled by

Code: Select all

http://www.sonic-rites.com/templates/rt_replicant/css/header-XXXX.css
, so maybe use that for your different pages (with Ninja Style).

If you just want to change the background image per page, there is some code on the RT forums contributed by a member for that (if i recall correctly). Look in the member submissions forum.

I don't know all that much about Replicant, having never used it, but I suspect MuffinDCC, who posted earlier in this thread, might just know a little about that templates inner workings.

Sorry if that isn't much help. You picked a tough (but very sexy) template to work with :)
http://twitter.com/mark_up.
Opinions expressed are mine alone and don't necessarily represent the views of any organisation I am associated with.

abushumays
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Wed Nov 26, 2008 7:02 pm

Page Class Suffix to call in a style sheet

Post by abushumays » Wed Nov 26, 2008 7:40 pm

My goal is, rather than modifying individual CSS classes based on the Page Class Suffix, to call in a whole stylesheet using that suffix.

looking at the code posted above:

Code: Select all

    <?php
    $menus     = &JSite::getMenu();
    $menu       = $menus->getActive();
    $pageclass = "";
       
    if (is_object( $menu )) :
    $params = new JParameter( $menu->params );
    $pageclass = $params->get( 'pageclass_sfx' );
    endif;
    ?>
    </head>
    <body class="<?php echo $pageclass; ?>">
i'm wondering if anyone thinks there should be any problem with linking in a stylesheet based on $pageclass, rather than using $pageclass to modify the class of <body>?

e.g. replacing the last two lines of the above with:

Code: Select all

<link rel="stylesheet" href="http://mywebsite.com/templates/mytemplate/css/<?php echo $pageclass ?>.css" type="text/css" />
with the various files ($pageclass).css containing the styles for pages with that page class suffix.

Is there any reason this shouldn't work in index.php for my site?

User avatar
MuffinDCC
Joomla! Explorer
Joomla! Explorer
Posts: 347
Joined: Wed Nov 22, 2006 9:07 am
Location: UK
Contact:

Re: Page Class Suffix in template code

Post by MuffinDCC » Wed Nov 26, 2008 9:18 pm

That seems a perfectly reasonable approach, just remove the class from the <body>.

creations
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Tue Dec 16, 2008 4:37 pm

Re: Page Class Suffix in template code

Post by creations » Tue Dec 16, 2008 4:44 pm

Hi, this code is great, exactly what I'm looking for!
It works perfectly in all browsers but IE6, I just couldn't get it to load my backgrounds there, and I want to have a different background on every page.

The last idea, with loading a new CSS file works in IE6 as well, but I'd rather use the body class than load so many CSS files. Any ideas?

Floddy
Joomla! Intern
Joomla! Intern
Posts: 57
Joined: Wed Sep 10, 2008 6:08 am
Location: Sweden
Contact:

Re: Page Class Suffix in template code

Post by Floddy » Mon Jan 05, 2009 10:06 pm

Hi,

Thanks a lot for this, it's exactly what I'm looking for. Saved me lots of searching time!

Regards,
Floddy

User avatar
bobbravo2
Joomla! Apprentice
Joomla! Apprentice
Posts: 39
Joined: Sun Jul 22, 2007 10:45 pm
Location: Orlando, FL
Contact:

Re: Page Class Suffix in template code

Post by bobbravo2 » Mon Jun 22, 2009 11:04 pm

MuffinDCC wrote:This code works for me and doesn't display any errors.

Code: Select all

<?php
$menus 	 = &JSite::getMenu();
$menu   	 = $menus->getActive();
$pageclass = "";
	
if (is_object( $menu )) : 
$params = new JParameter( $menu->params );
$pageclass = $params->get( 'pageclass_sfx' );
endif; 
?>
</head>
<body class="<?php echo $pageclass; ?>">
*This is my 3rd edit of this post with all the code lol :D *

Thanks this works beautifully!

User avatar
TomT
Joomla! Ace
Joomla! Ace
Posts: 1324
Joined: Thu Aug 18, 2005 5:50 am
Location: Amsterdam
Contact:

Re: Page Class Suffix in template code

Post by TomT » Mon Aug 31, 2009 2:37 pm

Thanks, works great :)

User avatar
kavaXtreme
Joomla! Intern
Joomla! Intern
Posts: 74
Joined: Tue Dec 13, 2005 9:56 pm
Location: Oregon
Contact:

Re: Page Class Suffix in template code

Post by kavaXtreme » Sat Sep 19, 2009 11:04 pm

Much appreciated!

A tutorial based on this thread can now be found here:
http://docs.joomla.org/Using_the_Page_C ... plate_Code
- Bible Yellow Pages: http://www.bibleyp.com

User avatar
ltempest
Joomla! Guru
Joomla! Guru
Posts: 600
Joined: Thu Aug 25, 2005 11:16 am
Location: Gloucester, UK
Contact:

Re: Page Class Suffix in template code

Post by ltempest » Mon Nov 23, 2009 3:41 pm

Does the page DOCTYPE matter when using this code?

I have followed the tutorial exactly and copied and pasted the code for item id, but nothing gets put in the body ID tag other than 'default' no matter what menu item I click on.

Any help most appreciated. I include my code below for reference:

Code: Select all

<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" >
 
 <?php
   $itemid = JRequest::getVar('Itemid');
   $menu = &JSite::getMenu();
   $active = $menu->getItem($itemid);
   $params = $menu->getParams( $active->id );
   $pageclass = $params->get( 'pageclass_sfx' );
 ?>

<head>
<jdoc:include type="head" />

<link rel="stylesheet" href="templates/<?php echo $this->template ?>/css/template_css.css" type="text/css" />
<link rel="stylesheet" href="templates/<?php echo $this->template ?>/css/test.css" type="text/css" />
<link rel="stylesheet" href="css/test.css" type="text/css" />

</head>

<body id="<?php echo $pageclass ? $pageclass : 'default'; ?>">
 	<div id="main">
		<div id="header_area"></div>		
		<?php if($this->countModules('user1')) : ?><jdoc:include type="modules" name="user1" style="xhtml" /><?php endif; ?>
        <div id="contentarea">
		<?php if($this->countModules('user2')) : ?><jdoc:include type="modules" name="user2" style="xhtml" /><?php endif; ?>
        <jdoc:include type="component" />
		<?php if($this->countModules('user3')) : ?><jdoc:include type="modules" name="user3" style="xhtml" /><?php endif; ?>
		<?php if($this->countModules('user4')) : ?><jdoc:include type="modules" name="user3" style="xhtml" /><?php endif; ?>
        </div>
		<div id="footer">
		<?php if($this->countModules('user5')) : ?><jdoc:include type="modules" name="user5" style="xhtml" /><?php endif; ?>
		<?php if($this->countModules('user6')) : ?><jdoc:include type="modules" name="user6" style="xhtml" /><?php endif; ?>
		<?php if($this->countModules('user7')) : ?><jdoc:include type="modules" name="user7" style="xhtml" /><?php endif; ?>
		</div>
	</div>
</body>
</html>

User avatar
TomT
Joomla! Ace
Joomla! Ace
Posts: 1324
Joined: Thu Aug 18, 2005 5:50 am
Location: Amsterdam
Contact:

Re: Page Class Suffix in template code

Post by TomT » Tue Nov 24, 2009 9:13 am

I placed the code in the head of index.php. You placed it before the head tag, try changing this.

_prakash
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Sun Nov 15, 2009 5:49 am

Re: Page Class Suffix in template code

Post by _prakash » Tue Nov 24, 2009 11:06 am

great work ....
I was trying to change the div classes inside the body, but the codes listed above is not working. Is that this works with the body tag only? If it is so please anyone help me out changing the div classes suffix according to selected menu..

User avatar
TomT
Joomla! Ace
Joomla! Ace
Posts: 1324
Joined: Thu Aug 18, 2005 5:50 am
Location: Amsterdam
Contact:

Re: Page Class Suffix in template code

Post by TomT » Wed Nov 25, 2009 7:07 am

_prakash wrote:great work ....
I was trying to change the div classes inside the body, but the codes listed above is not working. Is that this works with the body tag only? If it is so please anyone help me out changing the div classes suffix according to selected menu..
On http://leontinelieffering.nl/ i've got it working for a div inside the body. I Use it this way: <div id="content<?php echo $pageclass; ?>"><jdoc:include type="component" /></div>

mik0209jmla
Joomla! Apprentice
Joomla! Apprentice
Posts: 9
Joined: Mon Feb 02, 2009 7:36 pm
Location: Red Deer, Alberta, Canada
Contact:

Re: Page Class Suffix in template code

Post by mik0209jmla » Tue Jun 15, 2010 7:12 pm

Hello,

I have tried adding this code

Code: Select all

<?php
   $menus = &JSite::getMenu();
   $menu = $menus->getActive();
   $pageclass = "";
   
   if (is_object( $menu )) :
   $params = new JParameter( $menu->params );
   $pageclass = $params->get( 'pageclass_sfx' );
   endif; ?>
to the RT Mixxmag index.php template file just above </head>, but the results are not working as they should.

I have also added this code

Code: Select all

<body id="ff-<?php echo $fontfamily; ?>" class="<?php echo $fontstyle; ?> <?php echo $pageclass; ?> <?php echo $tstyle; ?> iehandle">
to the <body> tag. The other styles are part of the core coding developed by Rocket Theme. Here is the generated source for the <body> tag

Code: Select all

<body id="ff-mixxmag" class="f-default "Page class should be echoed here" style1 iehandle">
Only a double space is rendered in this spot instead of the page class suffix.

I have added the page class suffix to the menu item, but the code is not being rendered correctly.

I hope someone can help me with this issue and I thank you in advance for your time.

Joomla 1.5.10
RT Mixxmag template version 1.5.2

garstud
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Fri Apr 10, 2009 8:36 am
Location: France (South)

Re: Page Class Suffix in template code

Post by garstud » Mon Jun 28, 2010 12:55 pm

MuffinDCC wrote:This code works for me and doesn't display any errors.

Code: Select all

<?php
$menus 	 = &JSite::getMenu();
$menu   	 = $menus->getActive();
$pageclass = "";
	
if (is_object( $menu )) : 
$params = new JParameter( $menu->params );
$pageclass = $params->get( 'pageclass_sfx' );
endif; 
?>
</head>
<body class="<?php echo $pageclass; ?>">
Great, it works, thank you for this nice tips ;)

garstud
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Fri Apr 10, 2009 8:36 am
Location: France (South)

Re: Page Class Suffix in template code

Post by garstud » Mon Jun 28, 2010 1:01 pm

mik0209jmla wrote: Only a double space is rendered in this spot instead of the page class suffix.

I have added the page class suffix to the menu item, but the code is not being rendered correctly.
Hello,

Double white space ? it seems that no menu object was found !
The double white space appears when clicking on the menu you have added a suffix ?
Have you put the php code before the body tag ?

mik0209jmla
Joomla! Apprentice
Joomla! Apprentice
Posts: 9
Joined: Mon Feb 02, 2009 7:36 pm
Location: Red Deer, Alberta, Canada
Contact:

Re: Page Class Suffix in template code

Post by mik0209jmla » Mon Jun 28, 2010 3:08 pm

Hello,

I submitted a posting on the Rocket Theme forums and found out the problem was related to the parent menu item not being published. I tested it on a local server and everything is functioning as it should.

Thank you for your input.

harveybass
Joomla! Apprentice
Joomla! Apprentice
Posts: 31
Joined: Sun Sep 11, 2005 11:19 pm
Location: Brisbane, Australia
Contact:

Re: Page Class Suffix in template code

Post by harveybass » Tue Jan 04, 2011 12:58 am

does this code work in joomla 1.6? I have been trying with no success?

User avatar
gavjof
Joomla! Intern
Joomla! Intern
Posts: 64
Joined: Wed Nov 08, 2006 11:06 am

Re: Page Class Suffix in template code

Post by gavjof » Wed Jan 19, 2011 9:49 am

kavaXtreme wrote:Much appreciated!

A tutorial based on this thread can now be found here:
http://docs.joomla.org/Using_the_Page_C ... plate_Code
Great topic. Thanks for all the work. :D

A note: I believe there is a syntax error in the docs page.
By Active menu is:

Code: Select all

$pageclass = $params->get( 'pageclass_sfx' ));
This generates a syntax error while:

Code: Select all

$pageclass = $params->get( 'pageclass_sfx' );
works fine.

harveybass
Joomla! Apprentice
Joomla! Apprentice
Posts: 31
Joined: Sun Sep 11, 2005 11:19 pm
Location: Brisbane, Australia
Contact:

Re: Page Class Suffix in template code

Post by harveybass » Tue Mar 01, 2011 11:42 am

can anyone give me a working example of code for joomla 1.6

I am currently using this

-------------- in the head -------------
<?php defined('_JEXEC') or die('Restricted access');

$menus = &JSite::getMenu();
$menu = $menus->getActive();
$pageclass = "";

if (is_object( $menu )) :
$params = new JParameter( $menu->params );
$pageclass = $params->get( 'pageclass_sfx' );
endif;

echo '<?xml version="1.0" encoding="utf-8"?'.'>'; ?>

--------------in the body --------------
<?php if ($pageclass == "_home") { ?>


<?php } ?>

designsubway
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 151
Joined: Fri Apr 16, 2010 3:03 pm
Location: Scarborough, UK
Contact:

Re: Page Class Suffix in template code

Post by designsubway » Thu May 12, 2011 3:28 pm

For Joomla 1.6 use this in the head:

Code: Select all

<?php
$app = JFactory::getApplication('site');
$pageclass =  & $app->getParams('com_content');
?>
And then this for the <body> tag:

Code: Select all

<body class="<?php echo $pageclass ->get('pageclass_sfx'); ?>">
:)
Director / Designer at Betton Design Ltd, Scarborough.
https://bettondesign.co.uk/

webSlaveParis
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Thu Aug 04, 2011 4:28 pm

Re: Page Class Suffix in template code

Post by webSlaveParis » Fri Aug 05, 2011 11:44 am

Hello everyone,
that very usefull code is not working for me ! :(
I've tried both possibilities, placed them in different places in my index.php...
the $pageclass variable remains desparetely empty...

Anyone who's had the same problem and found a solution ?
Thanks for the help you could give.

Webslave
(Joomla 1.5.20)

designsubway
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 151
Joined: Fri Apr 16, 2010 3:03 pm
Location: Scarborough, UK
Contact:

Re: Page Class Suffix in template code

Post by designsubway » Sun Aug 07, 2011 6:22 pm

@webSlaveParis

My version won't work because it only applies to Joolma 1.6 and 1.7

I suggest you go back and read this thread properly for Joomla 1.5
Director / Designer at Betton Design Ltd, Scarborough.
https://bettondesign.co.uk/

webSlaveParis
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Thu Aug 04, 2011 4:28 pm

Re: Page Class Suffix in template code

Post by webSlaveParis » Mon Aug 08, 2011 7:02 am

I have read it properly and thouroughly... :(

HelenSims
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Tue Aug 09, 2011 5:31 pm
Contact:

Re: Page Class Suffix in template code

Post by HelenSims » Tue Aug 09, 2011 5:40 pm

Working perfectly for me. Thanks, really appreciate it

erhabe
Joomla! Apprentice
Joomla! Apprentice
Posts: 26
Joined: Thu Mar 18, 2010 1:56 pm

Re: Page Class Suffix in template code

Post by erhabe » Mon Jan 30, 2012 3:33 am

Hello

I added

Code: Select all

<?php
  $itemid = JRequest::getVar('Itemid');
  $menu = &JSite::getMenu();
  $active = $menu->getItem($itemid);
  $params = $menu->getParams( $active->id );
  $pageclass = $params->get( 'pageclass_sfx' );
?>
and

Code: Select all

<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/rhuk_milkyway/css/<?php echo $pageclass ?>.css" type="text/css" />
on my index.php file.
I put on menu page suffix place the suffixes and everything works perfect.
BUT i have problems with 2 components that see this only on the page that menu is linked on.
On other pages of the same component i got this

Code: Select all

<link rel="stylesheet" href="/templates/rhuk_milkyway/css/.css" type="text/css" />
Can someone help me to solve this problem because the css file cant be loaded.
Thank you

kshdzines
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Tue Nov 23, 2010 2:37 pm

Re: Page Class Suffix in template code

Post by kshdzines » Sat Mar 10, 2012 1:45 pm

MuffinDCC wrote:I modified the code so it was a bit leaner, it was a bit ... long winded as I was testing it out. So, for anyone wanted to implement it, just follows these steps:-

1. Open your template's index.php file (located in /templates/*template-name*/)

2. Find the </head> tag in the index.php, should be near the top area of the template
This sounds so great and exactly what I need...:-) BUT....my "index.php" for my template looks like this:

index.php
PHP script text

?><?php
/**
* @package yoo_neo Template
* @file index.php
* @version 5.5.1 August 2010
* @author YOOtheme http://www.yootheme.com
* @copyright Copyright (C) 2007 - 2010 YOOtheme GmbH
* @license YOOtheme Proprietary Use License (http://www.yootheme.com/license)
*/

// no direct access
defined('_JEXEC') or die('Restricted access');

// include config
include_once(dirname(__FILE__).'/config.php');

// load main template file, located in /layouts/template.php
echo $warp->template->render('template');

So, I go to the "template.php" and get this....


template.php
PHP script text

<?php
/**
* @package yoo_neo Template
* @file template.php
* @version 5.5.1 August 2010
* @author YOOtheme http://www.yootheme.com
* @copyright Copyright (C) 2007 - 2010 YOOtheme GmbH
* @license YOOtheme Proprietary Use License (http://www.yootheme.com/license)
*/

// get template configuration
include(dirname(__FILE__).'/template.config.php');

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->warp->config->get('language'); ?>" lang="<?php echo $this->warp->config->get('language'); ?>" dir="<?php echo $this->warp->config->get('direction'); ?>" >
<head>
<?php echo $this->warp->template->render('head'); ?>
<link rel="apple-touch-icon" href="<?php echo $this->warp->path->url('template:apple_touch_icon.png'); ?>" />
</head>

<body id="page" class="yoopage <?php echo $this->warp->config->get('columns'); ?> <?php echo $this->warp->config->get('itemcolor'); ?> <?php echo $this->warp->config->get('toolscolor'); ?> <?php echo $this->warp->config->get('frontpage'); ?> <?php echo $this->warp->config->get('webfonts'); ?>">

<?php if ($this->warp->modules->count('absolute')) : ?>
<div id="absolute">
<?php echo $this->warp->modules->render('absolute'); ?>
</div>
<?php endif; ?>........cont.

Can you please tell me where to insert this code??...:-(

I need just 1 page with a dk red background...I have this, but please look at the "wrapper" edge...it is still white. I need the whole page red...:-(

http://174.132.147.99/~renonati/index.p ... &Itemid=10

Thanks!
karen

Mihc
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Mon Aug 28, 2006 3:23 pm

Re: Page Class Suffix in template code

Post by Mihc » Fri Mar 16, 2012 1:41 pm

designsubway wrote:For Joomla 1.6 use this in the head:

Code: Select all

<?php
$app = JFactory::getApplication('site');
$pageclass =  & $app->getParams('com_content');
?>
And then this for the <body> tag:

Code: Select all

<body class="<?php echo $pageclass ->get('pageclass_sfx'); ?>">
:)
I tried this code in Joomla 2.5.3 and the body class is empty. Is it working in latest J! or i have to use some different code?

User avatar
LAMF
Joomla! Guru
Joomla! Guru
Posts: 761
Joined: Fri Jul 03, 2009 9:51 am

Re: Page Class Suffix in template code

Post by LAMF » Mon Mar 26, 2012 11:56 am

This works just fine but if I have an article that is not linked to from any menu object how can I apply a page class-suffix to that article?
Is it possible at all?

adelion
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Wed Nov 22, 2006 5:20 am
Contact:

Re: Page Class Suffix in template code

Post by adelion » Thu Apr 12, 2012 1:48 am

Here is a solution for 2.5.x users:

Code: Select all

<?php
  $itemid = JRequest::getVar('Itemid');
  $menu = &JSite::getMenu();
  $active = $menu->getItem($itemid);
  $params = $menu->getParams( $active->id );
  $pageclass = $params->get( 'pageclass_sfx' );
?>

<html>
<head>
<jdoc:include type="head" />
</head>

<body class="<?php echo $pageclass ?>">


Locked

Return to “Templates for Joomla! 1.5”