How do I force code within the node.tpl.php to only appear on full pages, and not on the frontpage ?

I am making modifications to my phptemplate , node.tpl.php but I don't want these modifications too appear on the frontpage.

Appatently the homepage also uses node.tpl.php.

Marcel
http://01wholesale.com
http://businessletters.com

Comments

Dublin Drupaller’s picture

I think you can use a thing called is_front you can use...or more to the point "if this isn't the front page..do this"..

if (!$is_front):

DO STUFF IF THIS ISN'T THE FRONT PAGE

endif;

Hope that helps..is_front definitely works with page.tpl.php...and assume it will work with node.tpl.php as well.

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

laura s’s picture

if ($page == 0): DO STUFF FOR PAGE DISPLAY
endif;

This works for node displays, taxonomy displays, any multi-node display. Not sure if the is_front query would do the same.

Conversely, you also can do:

if ($page != 0): DO STUFF FOR NODE-ONLY DISPLAY
endif;

===
Laura
pingVision

_____ ____ ___ __ _ _
Laura Scott :: design » blog » tweet

Dublin Drupaller’s picture

yep. good point Laura..that is probably better to use instead of the is_front..

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

pamphile’s picture

It worked... ! :)

Thanks to Laura and Dublin

Wholesale DIrectory
Business Letters
Football News

varunvnair’s picture

I realised this the hard way :-)

A theme developer should almost always use if($page==0) instead of if($is_front).

$is_front is set strictly for the front page. If you click on a taxonomy term then the resulting page (which looks like the frontpage but has only those nodes that are classified under that specific taxonomy term) does NOT have $is_front set.

Thanks everybody.

My Drupal-powered Blog: ThoughtfulChaos

robertgarrigos’s picture

I never have $is_front set, neither with the front page. I understand that front page can be any page especified in the main settings form. Have this been changed with v.4.6.6?

---
Robert Garrigos
Professional site:robert.garrigos.org

bradlis7’s picture

A good use for $is_front would be to hide the breadcrumbs. I'm doing that with a theme, so the padding and stuff isn't generated for the front page:

  <?php if (!$is_front && $breadcrumb != ""): ?>

    <?php print $breadcrumb ?>

  <?php endif; ?>

If you don't do that, it puts "

", or something like that on 'node'.

--
Bradlis7.com | Churchofchristnet

Jacob’s picture

On my Drupal 4.7.2 site $page is never set, regardless of if page is the homepage or not :(
I have one template for the homepage and another for the rest of the site. mysite.com/ works fine with $is_front , but mysite.com/index.htm (defined as such in settings) does not. Bug?

I found the solution that may be not perfect, buy works fine for me

if ($is_front || variable_get('site_frontpage', 'node')==$_REQUEST["q"]) {
    //put your homepage related stuff here
}

Regards,
Jacob.

chrisd’s picture

I'm not sure $is_front still works.

For me I had to replace $is_front with the test $_REQUEST["q"]=="" (which should evaluate to true on the main page www.yourSite.com)

So this code might display breadcrumb on all page but the home page (ie www.blabla.com or www.blable.com/Home_Page_As_Defined_In_Settings):

<?php if (!$_REQUEST["q"]=="" && !(variable_get('site_frontpage', 'node')==$_REQUEST["q"])) print $breadcrumb; ?>

Tchao,
Chris D.
Tech. articles with a WAMP+IIS+Drupal focus

Take a break: Guide to France

qwerty1234’s picture

I have Drupal 4.7.2 and $is_front seems to be never set

I use

if (drupal_is_front_page()) { /*What you wont*/ }
RobotHero’s picture

I had the same problem, so I used this. It works now.

JurriaanRoelofs’s picture

On my drupal 4.7 site, page is always set to 0, even on full-node views. how is that possible?

-------------------------------
http://www.sooperthemes.com/#-Drupal-Themes

jhuckabee’s picture

I'm noticing this too. $page never seems to be set. I'm on 4.7.3

Anyone know anything about this?

OpenChimp’s picture

I'm having this same problem. Using 4.7.3 In node.tpl.php if ($page == 0) { works fine to make the distinction, but it doesn't work in page.tpl.php

I don't know why this is, but now I can't distinguish between these page types within the page template, which is kinda important.

Anyone know of a fix or alternative?

Michael
www.webemulsion.com

pamphile’s picture

ok

Now how do I check if I am browsing a taxonomy ?

Marcel
http://www.acmetutorials.com

nevets’s picture

I use the following test to see if I am browsing taxonomy

if ( arg(0) == 'taxonomy' && arg(1) == 'term' ) {
  // Browsing taxonomy pages
}
idflorin’s picture

if ( arg(0) != 'taxonomy' && arg(1) != 'term' && !is_numeric(arg(1))) {
            return TRUE;
        }
        
   // browsing front page

return FALSE;


It's more than just the front page...

-----------------
Chic Velvet

cakka’s picture

$is_front = use this for template, like page.tpl.php

drupal_is_front_page() = use this in block, node or other

ms_johnson’s picture

i'm using this statement in page.tpl.php

i would like the front page to display flash
i would like the node 24 to display a single .png file
and i would like all other pages to display the javascript

<?php if ( $is_front ) : ?>
    <!-- param tags as necessary for your .swf -->
    <embed align="left" width="810" height="200" src="http://fredoniamountainfarm.org/flash/fpage_08182010.swf" allowscriptaccess="always"></embed><br><hr color="#cccccc">
<?php else if ($page == node/24) : ?>
<img src="http://chattanoogacares.org/graphics/banner/pageheader/CUT-UP.png">
<?php else ($page == 0) : ?>
<script LANGUAGE="JavaScript" TYPE="text/javascript">
<!-- 
pagetop(); 
// --> 
</script>
<?php endif; ?>

the front page and node 24 work perfectly. however, all other pages do not. they display the single .png file as well and not the javascript. i'm thinking

<?php else ($page == 0) : ?>

is not working. any ideas/suggestions?

thanks!
shane

[Added <code> and </code> tags: nevets]

nevets’s picture

Two things I see

1) There is no default "$page" in page.tpl.php, you could replace else if ($page == node/24)> with else if ( $node->nid == 24 ).

2) else ($page == 0) should just be else

(Side note, in $page == node/24, node/24 needs to be in quotes, ie 'node/24')