4

I'm building a really simple site and I came into this question now. The site has a few content types and one of them acts as a moderated wiki (only users with a certain role may create/edit that content). When viewing lists of these nodes or when viewing any node of that content type in full-mode I would like the site logo to be different. Say, instead of «My site», something like «My site [[wiki]]».

My first thought was tweaking context to change theme settings based on context. Too bad, I didnt find how to get that :/

I've been diving in the available answers here, but I dont seem to have an answer, though a couple of similar question tackle this subject through different systems:

  • One attempts to show different logo for different languages and relies and i18n and variable modules. see thread on i18n and variable
  • Second one adds a variable (though it is not clear if they put it directly in the node--type.tpl file (and i wouldnt like that :-/), by hand-writing the path to the desired image... see thread on tpl "abusing" :D

Any ideas on what is the best approach to get this custom logo for an specific content type?

Thanks :)

The code provided in the answer wasn't working properly, but I adapted the code and got it to work:

function YOURTHEMENAME_preprocess_page(&$vars, $hook) {
  if (isset($vars['node'])) {
  // If the node type is "blog" the template suggestion will be "page--node--blog.tpl.php".
   $vars['theme_hook_suggestions'][] = 'page__node__' . str_replace('_', '--', $vars['node']->type);
   }
}

With this function I got a tweakable and customized page.tpl.php. Now I only need to change the $logo value for this content type or add extra settings to the theme, as hard-coding the url path for the alternative logo seems inelegant :)

3
  • 2
    I see this over and over again where we (including me) try to over-complicate something as simple as this by look at writing custom code. Disable logo in theme settings and place your logos in a static blocks. Then use your block settings to place them by content type and language. Dead simple. No custom code. Jan 27, 2013 at 16:00
  • @NigelWaters :) yup... it probably is better to deactivate logo and then place blocks with context... yup. Keepint it simple :D Thanks!
    – versvs
    Jan 27, 2013 at 16:07
  • Yeah I recently went through something similar where block titles had to be hyperlinks and the first word in every block title needed to be a different color. Tried hook this/that, tpl changes, hack, hack, hack. Simply not using block titles all together and placing text in the block with the h2 tags to act as "block titles" was a very easy solution. Spent hours trying to do something that was overly complicated and unnecessary. Jan 28, 2013 at 2:41

1 Answer 1

4

The simplest way would be to create a tpl for the content type to do that you can follow the below steps

First create a preprocess_page function as given below. This would go into the template.php file.

function YOURTHEMENAME_preprocess_page(&$vars) {
  if (isset($vars['node']->type)) {
    $vars['theme_hook_suggestions'][] = 'page__' . $vars['node']->type;
  }
}

now you can create a new page.tpl per content type something like

page__CONTERNTTYPENAME.tpl.php

You can copy the entire content of the existing page.tpl.php into this and replace the logo with the desired logo.

in zen theme the logo is in the page.tpl is printed as follows

<?php if ($logo): ?>
      <a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home" id="logo"><img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" /></a>
    <?php endif; ?>

here you can replace the image src with the direct path to your logo.

3
  • Thanks for the fast reply, Mohammed. I was looking to add sort of a conditional-setting in theme options, maybe a context (if it is possible at all to add new a "reaction-type"). But your solution goes directly to the problem and i guess it would be enough... :)
    – versvs
    Jan 26, 2013 at 19:15
  • 1
    by the way if your need is just to change the logo then the condition would also work well. you can use the $node->type to set the logo of your choice . Jan 26, 2013 at 19:18
  • I finally made a function that is a variation of your code
    – versvs
    Jan 26, 2013 at 23:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.