Ahmed Fraz
Blogger

How to Display Author Names in Blogger Templates

This guide explains different methods to display author names in Blogger templates with proper fallback handling and profile links.

Basic Author Name Display

The simplest way to show the author name in a Blogger template:

<!-- Basic Author name -->
<b:if cond='data:post.author'>
    <data:post.author.name/>
</b:if>

This will display the author name only if it exists.

With Fallback for Missing Authors

To handle cases where author information might be missing:

Method 1: Using b:eval

<!-- Author name with fallback -->
<b:eval expr='data:post.author ? data:post.author.name : "Anonymous"'/>

Method 2: Using b:else

<!-- Author name with fallback -->
<b:if cond='data:post.author'>
    <data:post.author.name/>
<b:else/>
    Anonymous
</b:if>

Linking to Author Profiles

To make the author name clickable when a profile URL exists:

Basic Profile Link

<!-- Author name with profile link -->
<b:if cond='data:post.author'>
    <b:if cond='data:post.author.profileUrl'>
        <a expr:href='data:post.author.profileUrl'>
            <data:post.author.name/>
        </a>
    <b:else/>
        <data:post.author.name/>
    </b:if>
</b:if>

Profile Link with Fallback

<!-- Complete solution with profile link and fallback -->
<b:if cond='data:post.author'>
    <b:if cond='data:post.author.profileUrl'>
        <a expr:href='data:post.author.profileUrl'>
            <data:post.author.name/>
        </a>
    <b:else/>
        <data:post.author.name/>
    </b:if>
<b:else/>
    Anonymous
</b:if>

Best Practices

  • Always include a fallback for cases where author data might be missing
  • Consider adding CSS classes for styling author names consistently
  • For team blogs, you might want to show author profile pictures as well
  • Test your template with posts that have and don't have author information

Advanced Usage

For more complex implementations, you can combine this with other Blogger data variables:

<div class="post-meta">
    <span class="post-author">
        <b:if cond='data:post.author'>
            Posted by 
            <b:if cond='data:post.author.profileUrl'>
                <a expr:href='data:post.author.profileUrl'>
                    <data:post.author.name/>
                </a>
            <b:else/>
                <data:post.author.name/>
            </b:if>
        </b:if>
    </span>
    <span class="post-timestamp">
        on <data:post.timestamp/>
    </span>
</div>
comment url
Post a Comment