I'm building a site where the higher-ups have requested a couple different Site names be shown based upon a visitor's location. Essentially, it comes down to making sure the right "marketing" name gets used as part of the site name in the top of the browsing window. While I thought I had encountered my solution, it would appear that the exact method below will need some tweaking to be interpreted properly by the Genesis Sub-Theme I've created.
Changing the site logo and name for each section based on path: http://drupal.org/node/154099
The code it suggests is as follows:
<?php
/**
* This snippet overrides the logo and site name when users
* are viewing certain sections of your site.*/
function _phptemplate_variables($hook, $variables = array()) {
switch ($hook) {
case 'page':
if ((arg(0) == 'blog')) {// changes the logo and site name when viewing blogs
$variables['site_name'] = 'blog section name'; // change the site name
$variables['logo'] = '/path/to/newlogo/logo.png'; // change the site logo
}
if ((arg(0) == 'image')) { // changes the logo and site name when viewing images
$variables['site_name'] = 'user section name'; // change the site name
$variables['logo'] = '/path/to/newlogo/logo.png'; // change the site logo
}
if ((arg(0) == 'admin')) { // changes the logo and site name when viewing admin pages
$variables['site_name'] = 'admin section name'; // change the site name
$variables['logo'] = '/path/to/newlogo/logo.png'; // change the site logo
}
if ((arg(0) == 'product')) { // changes the logo and site name when viewing product pages
$variables['site_name'] = 'admin section name'; // change the site name
$variables['logo'] = '/path/to/newlogo/logo.png'; // change the site logo
}
break;
}
return $variables;
}
?>
Would someone be willing to enlighten me on how to adapt this to Genesis' framework? All I need is to be able to set the different site name for when I'm at let's say http://www.example.com/itemA and http://www.example.com/itemB - the items affected by this are just standard pages, with no other special needs or unique content types from CCK.
Comments
Comment #1
Jeff Burnz commentedYou need to use the themeName_preprocess_page function in your subthemes template.php file, the above code is for Drupal 5. You don't need the switch hook, case and return variables statements, otherwise settings variables based on URL args will work just fine.
e.g...
Just remember that Genesis already preprocess's these vars in the base themes preprocess fucntions, so you will probably need to account for that, which ever way you choose to.
Heres the relevant snippet from genesis_preprocess_page...
Comment #2
GatorBat commentedThanks for the assistance Jeff. I copied your snippet into my sub-theme's template.php (without the open/closing PHP tags of course), adjusted the function name to be mysubtheme_preprocess_page, but as you cautioned, it did not alter the Site name displayed, presumably because the base Genesis theme has already done the preprocessing. I'm not sure how to account for this change in the main Genesis template.php theme, as I've always thought we should avoid altering the main Genesis theme if possible, and sadly, I'm no expert in programming/PHP/Drupal API/Theme processing. Would you be able to assist me a bit further?
Edit: Forgot to mention I did clear my cache after applying the changes to my subtheme's template.php via /admin/settings/performance - though no change was witnessed.
Comment #3
Jeff Burnz commentedPaste the code you are using here, I need to see what you are actually using.
I assumed you understood by reading the instructions in the template.php page that you need to chane the name of the function to match your theme name
genesis_SUBTHEME_preprocess_page to mythemename_preprocess_page
Comment #4
GatorBat commentedI did indeed change the name of the function to match my theme's name. My sub-theme is located in a subfolder named ufspc_v1alt, and I am adding the code you suggested in the template.php of that sub-theme folder. I made sure I edited the code to include my theme's name as part of the function I inserted into the into the template.php
I did NOT MODIFY the template.php included in the Genesis themes folder located in /sites/all/themes.
Comment #5
Jeff Burnz commentedOK, a couple of things here:
1) confirm your URL is this: mysite.com/Stuff
2) code you pasted is broken - missing the closing single quote on the last line: should be $vars['site_name'] = 'Stuff Page';
3) I'm assuming you just want to print out the words "Stuff Page", but not as a link, because you are not including any of the link code such as used in genesis core. Remember, you are resetting the entire contents of the variable, so that link stuff will not automagically be included, that is why I pointed it out, if you want it to be a link you have to include that as well. e.g something like this
One last thing - is this really the machine name of your theme (the name of the info file) "ufspc_v1alt", you said it was in the folder named that, but by memory the folder name is not important in this instance (it is important for when drupal is building paths to the theme directory, it must match the machine name of the theme), but here its the name of the info file that counts.
Comment #6
GatorBat commentedMuch obliged for your continued help. Just to confirm, yes, ufspc_v1alt.info is the machine name of info file, I just kept the directory named the same for sanity's sake on my part.
1) Aye, URL should be mysite.com/Stuff (content has a URL Alias to this node/set of nodes)
2) Thanks for catching the missing semicolon, ironically the same missing semicolon wasn't present in #5, should be $section_title = 'blog section name'; Once I corrected this and added your suggested code into the template.php in the sub-theme folder, admin sections would output a huge text that said admin section name at the top of the page.
3) Jeff, I'm afraid I haven't totally made it clear on what I'm trying to achieve, or we may simply not be there yet because I am not adept at coding. I'm trying to see if it is possible to have the site name that we input into /admin/settings/site-information in the "Name" field be overridden based on a node path, and this overridden value be displayed at the very top of the web browsing window (in the same section as most would find their minimize, maximize, and close buttons). I don't need links or anything special or clickable, just way (if even possible) to have a different value for the site name/title based upon node path. It's essentially the same as altering the standard title tags one would place in the header of a straight HTML page, but I didn't see an easy way to accomplish this, seeing as site name inserts this value into the node and page templates in most themes.
Comment #7
Jeff Burnz commentedWell thats the Page Title, not the site name.
You can use the same logic and set your own var or use drupal_set_title.
Comment #8
GatorBat commented/em faceplant - Thanks Jeff, that would explain why it was targeting/printing out where it was. I'll have to see if I can pull together some sample code of my own or find a way to use drupal_set_title properly- the API scene is not a good area for me, as if you couldn't tell :P If I can get it to keep the node's title, but append something different than the site_name that current gets appended, I'd be in business.
Comment #9
Jeff Burnz commentedHey, just a thought, have you looked at the Page Title module, frankly I havent used it for a long time but I wonder if it has some magical new feature that allows you to set page titles for entire sections (used to be for just per node, and front etc), but I heard its come a long way, maybe a solution there?
Comment #10
GatorBat commentedPure Genious, Jeff! I hadn't done another round of Google searches now that you'd put me on the right path that I needed to set Page Titles instead of Site Names. I've read through the documentation on that module, and it seems like just what the doctor ordered. Thank you very much for your continued assistance and patience with me. I'd mark this issue closed, as an early round of testing with this module on a test install seems to provide exactly what I need.
Comment #11
Jeff Burnz commentedCool man, great stuff, changing the title back to the original since there is code here that could be useful to someone else searching around.