I am trying to use Bloginfo on a church's website. If you look at The Rector's Pen blog, it should say "The Rector's Pen" rather than "tim's blog" in the title. But it doesn't. I've followed the "Readme" but to no avail. Please assist.

Thanks in advance.

Comments

mfer’s picture

I'm not sure you understand what the module does. It creates a block that you have to enable and place in a region. It doesn't replace the title that is in the page.tpl.php as $title.

If you want to do the replacement with the bloginfo module to do your title and description on the blog page do this. Enable the bloginfo module. Place a region just above your content section. It may be the header region, one of the sidebar regions you aren't using, or you can create a new one. Place the block in that region at /admin/build/block.

Then, in your page.tpl.php file replace print $title; with:

if (arg(0) != 'blog' || $node->type != 'blog') { print $title; }

This will have the title not show up on blog nodes and blog listings.

Is this what you are looking for?

mfer’s picture

oops.. I meant for the second one to be:

if (arg(0) != 'blog' && $node->type != 'blog') { print $title; }
zanlus’s picture

I see what you are suggesting, but that isn't what I want to do. The result of your suggestion is that the title from blogs are subsequently removed.

The description of bloginfo says, "The bloginfo module adds a blog title and description to your blogs." If I have correctly understood your response (which I greatly appreciate, by the way), the module doesn't add a blog title to the blog. Rather, it produces a block that represents the blog with a title of your choosing. However, Drupal continues to recognize the blog as "$user's blog" (in this case "tim's blog"). If you have any suggestions about how to change that, I would appreciate your advice.

Many thanks for your help and I'm sorry that I didn't understand more completely what the module is capable of doing.

Sincerely,

Ross

mfer’s picture

ok, the bloginfo doesn't do quite what you are looking for.

There are a couple ways you can get what you are looking for. It depends on if you want to separate your business logic from your presentation. How many different pages do you want this change to appear on? Just the one blog or several pages?

mfer’s picture

Status: Active » Closed (fixed)

Marking as closed. If this is not taken care of please re-open the issue

udvranto’s picture

You code does not work for me. When I click "My Blog" the $title is not replaced. I am using pathauto module. Does that affect? In Andreas 01 template I have this line

<?php drupal_set_message(arg(0)."<br>".arg(1));
if ($title && (arg(0)!='blog' || (arg(0)=='blog' && arg(1))) ) { ?><h2 class="title"><?php print $title ?></h2><?php } ?>

The drupal_set_message prints inconsistent info for arg(0), sometimes it is 'blog', sometimes it is 'node'.

mfer’s picture

The code above does not replace the title. It conditionally removes/displays it.

if (arg(0) != 'blog' || $node->type != 'blog') { print $title; }

This says that if arg(0) is 'blog' than don't display the title. You'll find this with urls like /blog/1 or /blog/2. This is not affected by URL aliasing.

Second, it checks the node type that's being displayed. If the node type is 'blog' than it doesn't show the title. In the second case I am not checking to see what arg(0) is but what type of node something is if there is a node loaded.

in all other cases it does. This should work in any phptemplate theme code in your page.tpl.php file.

The intent of this is to turn off the title so you can use the bloginfo module in that titles place

udvranto’s picture

For those who wants to replace the blog title "%users Blog" to bloginfo title here is how you do it:

This is for andreas01 template

template.php
========

// $Id$
function andreas01_regions() {
  return array(
       'left' => t('left sidebar'),
       'right' => t('right sidebar'),
       'content' => t('content'),
        'contentheader' => t('content header'),
       'footer' => t('footer')
  );
}

page.tpl.php
=======
Change the following :

	<div id="content">
	  <div id="content-wrap">

        <div id="breadcrumb">
         <?php print $breadcrumb ?>
        </div>

        <?php if ($mission) { ?><div id="mission"><?php print $mission ?></div><?php } ?>
        <?php print $help ?>
        <?php print $messages ?>

        <?php if ($title) { ?><h2 class="title"><?php print $title ?></h2><?php } ?>

        <div class="tabs"><?php print $tabs ?></div>

        <?php print $content; ?>

      </div>
      
	</div>

TO:

	<div id="content">
	  <div id="content-wrap">

        <div id="breadcrumb">
         <?php print $breadcrumb ?>
        </div>

	      <div id="content-header">
        <?php if ($contentheader) print $contentheader; ?>
        </div>

        <?php if ($mission) { ?><div id="mission"><?php print $mission ?></div><?php } ?>
        <?php print $help ?>
        <?php print $messages ?>

        <?php if ($title && !$contentheader) { ?><h2 class="title"><?php print $title ?></h2><?php } ?>

        <div class="tabs"><?php print $tabs ?></div>

        <?php print $content; ?>

      </div>
      
	</div>
mfer’s picture

mr.j’s picture

Instead of inserting special content regions, and adding blocks, and modifying a template I prefer to do it this way. In your template.php, edit _php_template_variables function like so:

function _phptemplate_variables($hook, $vars) {
  if ($hook == 'page') {
    
    // START ADDING HERE
    if (arg(0) == 'node' && is_numeric(arg(1))) {
      $node = node_load(arg(1));	
    }
    if (((arg(0) == 'blog' && is_numeric(arg(1))) || $node->type == 'blog')) {
      if (arg(0) == 'blog') {
        $authorid = arg(1);
      } else if ($node->type == 'blog') {
        $authorid = $node->uid;
      }
      $results = db_query("SELECT title, description, format FROM {bloginfo} WHERE uid = %d", $authorid);
      if ($results && mysql_num_rows($results) > 0) {
        $bloginfo = db_fetch_object($results);
        $vars['title'] = check_plain($bloginfo->title);
        $vars['blogdesc'] = check_markup($bloginfo->description, $bloginfo->format, false);
      }
    }
    // END ADDING

    return $vars;
  }
  return array();
}

This will overwrite the title on blog pages without any other changes, and provide you with an extra variable 'blogdesc' which you can use in your page template if you want.

It would be better if the module supplied these variables via a function - instead I had to copy the code out of the bloginfo_block() function.

mr.j’s picture

Sorry I cannot edit the previous post. It has a bug in that it replaces the title of all blog entries within the blog, as well as the main blog page. Instead replace that middle section between my marked comments with this code and it will only replace the title on the main blog page (ie /blogs/user):

    if (((arg(0) == 'blog' && is_numeric(arg(1))))) {
      $authorid = arg(1);
      $results = db_query("SELECT title, description, format FROM {bloginfo} WHERE uid = %d", $authorid);
      if ($results && mysql_num_rows($results) > 0) {
        $bloginfo = db_fetch_object($results);
        $vars['title'] = check_plain($bloginfo->title);
        $vars['blogdesc'] = check_markup($bloginfo->description, $bloginfo->format, false);
      }
    }
level02’s picture

that code worked! and it would be perfect for tim's blog!

now how do I modify the teaser $links to read '($bloginfo->title)' instead of 'User's Blog'...

could it be a simple template.php function?

sam moore’s picture

Here's how you change the page title (in the HTML <head> section) so it'll show up as I think you want in the title bar of your browser:

  • open modules/blog.module
  • find the line drupal_set_title($title = t("@name's blog", array('@name' => $account->name)));
  • replace that line with this:
     /************************************************************************************************************************/
     // Use Blog Info title instead of "<username>'s Blog"   
     //drupal_set_title($title = t("@name's blog", array('@name' => $account->name)));
     $results = db_query("SELECT title FROM {bloginfo} WHERE uid = %d", $account->uid);
                         if ($results && mysql_num_rows($results) > 0) {
                                 $bloginfo = db_fetch_object($results);
                                 $blogtitle = check_plain($bloginfo->title);
                         }
     drupal_set_title($title = t("@newtitle", array( '@newtitle' => $blogtitle)));
     /************************************************************************************************************************/
    

Obviously you can remove the commented asterisks, but I find them helpful later when I can't remember what I hacked :-)
Also I left the original code in place, just commented it out.

sam moore’s picture

Here's a hack for the links at the bottom of each blog entry (currently these will say "<username>'s blog"; you probably want them to say "<Blogtitle>").

  • Again, open up blog.module
  • Now find the function blog_link (starts with
    function blog_link($type, $node = NULL, $teaser = FALSE) {<code )
    <li> replace the whole function with this:
    <code> /************************************************************************************************************************/
    /**
     * Implementation of hook_link().
     */
    function blog_link($type, $node = NULL, $teaser = FALSE) {
      $links = array();
       $results = db_query("SELECT title FROM {bloginfo} WHERE uid = %d", $node->uid);
                         if ($results && mysql_num_rows($results) > 0) {
                                 $bloginfo = db_fetch_object($results);
                                 $blogtitle = check_plain($bloginfo->title);
                         }
    
      if ($type == 'node' && $node->type == 'blog') {
        if (arg(0) != 'blog' || arg(1) != $node->uid) {
          $links['blog_usernames_blog'] = array(
      //      'title' => t("@username's blog", array('@username' => $node->name)),
             'title' => t("@blogtitle", array( '@blogtitle' => $blogtitle)),
           'href' => "blog/$node->uid",
    //        'attributes' => array('title' => t("Read @username's latest blog entries.", array('@username' => $node->name)))
            'attributes' => array('title' => t("Read the latest entries from @blogtitle.", array( '@blogtitle' => $blogtitle)))
          );
        }
      }
    
      return $links;
    }
     /************************************************************************************************************************/
    

The line with "Read the latest entries..." fixes the tooltip.

Now, for some reason, this only works when you're logged in - unauthenticated users still get "<Username>'s blog".
Maybe I'll figure that out later...

sam moore’s picture

Sorry, failed to close a <code> tag in the last post - write back if you can't figure it out.

level02’s picture

Works! On a local setup all users can see blogtitle using the above code and the page is also titled blogtitle thanks to post #13. Now it would be nice to render the & #039;'s as apostrophes... I'm sure i can find how to do that somewhere. (ex. blogtitle = The Dog's Breakfast renders: The Dog& #039;s Breakfast.) Also looking at the code and with the template function, I'm on my way to figuring this out.

thanks

level02’s picture

I used filter_xss instead of check_plain to fix the apostrophes after finding this page, and it seems to work.

mr.andrey’s picture

Here is a simple solution, add this to the bottom of your node.tpl.php

  /**
   * Fix the problem when a blog overrides title of the blog listing page.
   * 	reason why this works is that pathauto is configured to list all blogs
   * 	under /blogs/<name>, so the only time /blog is used is for user's blog list:
   * 		/user/bobab
   * 		/user/5
   */
	if (arg(0) == 'blog') {
		drupal_set_title($node->name."'s blog");
    }

This is simple, because $node->name (author's name) is available to the teaser listings of nodes, so a simple call to drupal_set_title can fix this.

Note the "if" statement: with my setup, this is all I need, since I list all my blogs under /blogs with pathauto, but if you list your blogs under /blog, you may want to do another check so this doesn't override all of the titles for your blogs as well.

Best,
Andrey.

goose2000’s picture

Oh this is a very mis-leading module, in name and description of what it does. I'm with the 1st guy.

"I am trying to use Bloginfo on a church's website. If you look at The Rector's Pen blog, it should say "The Rector's Pen" rather than "tim's blog" in the title. But it doesn't. I've followed the "Readme" but to no avail. Please assist."

darumaki’s picture

Status: Closed (fixed) » Active

When I try this code above all it does is remove the user's blog link it doesn't replace anything that I can tell or am I missing something

mfer’s picture

What is it you are trying to do with this module?

drein’s picture

ok... the only problem is what is best solution?
I'm a bit confusing, I see 3 or 4 manners to display title page of bloginfo, but don't you think that the best thing is to patch the module bloginfo itself?
ok I' not able to make this, but I think that it should be better patch bloginfo rather than the core blog module.
Also unofficial patch are appreciated.
thanks.

Delta Bridges’s picture

Any follow up on this?
Thanks,
Expat9

mr.andrey’s picture

Hello there,

Just to follow up on #18. In order for that solution to work, you need to have pathauto installed and have it rewrite users' blogs to /blog/ or /blog/.

(arg(0) == 'blog') looks in the url for the first argument, so for example in site.com/blog/babushka, first argument arg(0) is "blog", second argument arg(1) is "babushka".

You can change the names, but it's important for user's blog and the actual blog entry to have different art(0).

I've not looked into this in a while, the tweak seemed to fix the problem and I haven't heard about it having problems from our members since.

All the Best,
Andrey.

Delta Bridges’s picture

Thanks for the feedback :)
I will try it out and report here.
FYI, I just read an interesting discussion about removing Blog from core:
http://drupal.org/node/233301

Expat9

NNois’s picture

Hello,
I've followed this tread, it work just gread ! only a missing thing is the pathauto URL...
is it possible to use the userblog title (from bloginfo module) in pathauto ?

markwa’s picture

Title: Failure to Replace Blog Title » Just needed to remove ...'s blog... from My Opinions's blog

All I wanted to do was, for example, remove ...'s blog... from My Opinions's blog, so that the blog title would be displays as simply My Opinions. I don't have any problem asking my bloggers to use their blog title as there logon username. But it was annoying that the ...'s blog... showed up in the title.

The fix was easy. In the theme subidrectory, replace:

<h1 class="title"><?php print $title ?></h1>

with:

        <?php 
           $title_rev = $title;
           if ( (arg(0) == 'blog' || $node->type == 'blog')
                && strpos($title_rev, "'s blog") > 0)
           {
           	$title_rev = substr($title_rev, 0, strlen($title_rev) - 7);
           }
        ?>
        <h1 class="title"><?php print $title_rev ?></h1>
kmadel’s picture

In 6.4 the following template.php function works to replace the blog listing and individual blog page titles as well as the the head page title:

/**
* Override or insert PHPTemplate variables into the page templates.
*
* @param $vars
* A sequential array of variables to pass to the theme template.
* @param $hook
* The name of the theme function being called ("page" in this case.)
*/
function themename_preprocess_page(&$vars, $hook) {
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(arg(1));
}
if (((arg(0) == 'blog' && is_numeric(arg(1))) || $node->type == 'blog')) {
if (arg(0) == 'blog') {
$authorid = arg(1);
} else if ($node->type == 'blog') {
$authorid = $node->uid;
}
$thisUser = user_load(array('uid' => $authorid));
$title = $thisUser->profile_first_name .' '.$thisUser->profile_last_name.' - '.$thisUser->profile_position;
$vars['title'] = $title;
$vars['head_title'] = $title;
}
}

vikingew’s picture

Ok just reaching out check if someone still use this? It's been a long time I know, but I've been to heaven and back, no kidding. I can tell they have no computers there...