How to tell if there are nodes on a page
On my CRO site, I wanted to have a border around pages that have no nodes on them. This makes them match with the pages that are just one node. But I went nuts trying to find a way, in page.tpl.php, to determine if the page has nodes on it. Telling if it's a single node is easy because $node will be defined but there isn't any way I found to tell, for example, a teaser list view page from a table view page. I want the border around the table view page but not around the teaser view. I spent a lot of time looking through the defined vars and trying this and that and finally hit upon the solution.
merlinofchaos had suggested, when I initially was asking how to tell a teaser view from a table view, to put a global variable in the argument code. Well, that would work, but I didn't want to have to mod every view for this so I kept looking. Then it dawned on me that I can use a similar idea.
So what did I end up doing? I put this in function _phptemplate_variables in template.php:
<?php
case 'node':
// Set a global variable is the page has one or more node on it
// Used by the theme to wrap pages with no nodes
global $nodeonpage;
$nodeonpage = TRUE;
?>If there's at least one node on the page, it hits that and, bam, global variable set. Then I just need to check if that variable is true in page.tpl.php. Cool beans. :)
Michelle