0

I'd like to put a canned footer at the bottom of every blog post which has it's own content type. My blog posts can have comments so I'd like the footer boiler plate to be at the end of the post content but before the "Add new comment" header. I am NOT talking about a general footer for the entire site. What's the drupal way to achieve this?

2

More tricky way is to add a region in a node.tpl.php used in your blog posts. To do this, in your custom theme add the following code to template.php file

function mytheme_preprocess_node(&$variables) { 
  // List of all regions for the current theme
  foreach (system_region_list($GLOBALS['theme']) as $region_key => $region_name) {
    // Add content to $region variable
    if ($blocks = block_get_blocks_by_region($region_key)) {
      $variables['region'][$region_key] = $blocks;
    }
    else {
      $variables['region'][$region_key] = array();
    }
  }
}

Then copy node.tpl.php to your custom theme and then place the following code between any HTML tag.

print render($region['region_name']);

That way, you can have region named blog_footer, and put there whatever you want.

Taken from this answer.

2

I see 3 pretty easy solutions :

  1. (The easiest) You add a new field textarea to your blog content type. You configure its default value to the content you want (your blog footer content) which can be html (so you're free to type in whatever you want). Then configure the display of your blog post to have this field as the last one displayed. Done.

  2. You can add a entity_reference field (Entity reference module) to your blog content type. Then create a node which represent your footer, and use it as your default entity_reference field value for your blog content type. (Then you'll have to configure your display modes however you want it ...)

  3. You can probably do this with a hook_form_alter() and insert your footer directly in the form

Hope it helps

  • 1
    I like the first one because it allows flexibility to use the footer or change it or not show it at all. However, it doesn't seem to affect existing blog posts. Also one downside is changing the default won't change existing blog posts either.. – User May 18 '13 at 20:05
  • True, the 1 solution is not that flexible. Actually you should consider solution 2 : (a) As it will be an entity reference, if you change the referenced node content, it will be updated in all your blog posts. (b) If the entity reference field is mandatory and have a default value, I think it might have an impact on all the existing blog post (this trick might also work with the solution 1) Or you still have solution 3 : Create a node which body is your footer, and programatically load it in your blog post rendering (hook_form_alter) – liupascal May 19 '13 at 0:19
  • Or solution 4 : (a) Create a block with the footer content you want, and use Block reference to reference it in your blog content type. Now that you got your rendering (b) Try the mandatory + default value trick to force existing content to call the block as you want it ! – liupascal May 19 '13 at 0:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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