Friday, April 16, 2010

Putting A Post At The Top (A "Welcome" Post) - Part 2

Many people have asked how they can have a Welcome or Index message in their blog. I have a Welcome message, at the top of Nitecruzr Buzz, or on this blog, for instance.

This blog uses a text gadget, positioned above the post gadget, which leaves a gadget that shows up on every page. On Nitecruzr Buzz, I used a future dated post, so my "Welcome" showed up only on the "Home" page. Neither solution was optimal.
  • A true "Welcome" message should show up only on the "Home" (first) page. A text gadget shows up on every page.
  • A future dated post shows up only on the "Home" page, but it shows up in the Archive index with a future date.


Today, I fixed my Buzz Welcome message, so it only shows up on the "Home" page, and it does not show up as a post, in an archive index. What I now have is a Text gadget, that only displays on the "Home" page. Here's how you do that.

First, (you should have to ask?) backup the template. Then add a Text gadget to the page, and position the gadget just above the post gadget. Give it a snappy title, "Welcome To My Blog!".

Then tweak the new gadget.
  1. Identify the gadget to be tweaked.
  2. Edit the template.
  3. Locate and unfold the code for that gadget.

<b:widget id='Text1' locked='false' title='WelcomeMessage' type='Text'>
<b:includable id='main'>
  <!-- only display title if it's non-empty -->
  <b:if cond='data:title != ""'>
    <h2 class='title'><data:title/></h2>
  </b:if>
  <div class='widget-content'>
    <data:content/>
  </div>

  <b:include name='quickedit'/>
</b:includable>
</b:widget>

Add two simple lines of code, shown below in bold red face.

<b:widget id='Text1' locked='false' title='WelcomeMessage' type='Text'>
<b:includable id='main'>
<b:if cond='data:blog.url == data:blog.homepageUrl'>
  <!-- only display title if it's non-empty -->
  <b:if cond='data:title != ""'>
    <h2 class='title'><data:title/></h2>
  </b:if>
  <div class='widget-content'>
    <data:content/>
  </div>
</b:if>

  <b:include name='quickedit'/>
</b:includable>
</b:widget>

Note that the proper location of both the "<b:if cond='data:blog.url == data:blog.homepageUrl'>" and complementary "</b:if>" is crucial to the success here. Conditional tags must be properly located, and paired.

Save the change. Edit the text gadget as displayed on the blog, and remove the "WelcomeMessage" title. And of course, backup the template, again. And, it's done.

Now, if you want a dynamic "Welcome" page - maybe one based on posts published to a given label, you can do that too, with just a bit more work. And there are several variations on the "if" statement, that will let you selectively display (or not display) your gadget on other specific pages.
An easy alternative solution for this need, more recently offered, would be to use a static page, and a redirected Home page.

>> Top

24 comments:

mrclm said...

This. Is. Amazing. Seriously, thanks for putting this guide together. Works perfectly - used it at Waseca VBS site.

eo said...

Thank you!

I had two big problems.

1. No permanent "Welcome Post" at top, and

2. The BIG problem: only 1-2 posts showing up on home page. I did your answer to #1 and it also fixed #2!

Yeah.

By the way, do you know why doing #1 also has appeared to fix #2?

Thanks again, Sarah

amy said...

thanks for the clear instructions. it worked, but is there anyway to get rid of the "No posts" message?

Chuck said...

Amy,

"Showing 0 posts" is the status message, which can be removed by editing the post template.

Women At the Well said...

Thanks, it worked, but how do I have a photo only appear on the Home page?

Chuck said...

Women,

Why not add a Photo gadget, and setup the Photo gadget to appear on the Home page - just as you do an HTML / Text gadget?

Rob said...

Thank you, thank you! Now we have a blog customized to be more like a site for our fledgling Gourmet Nut business.Great resource.

J.S.Watts said...

I just tried and the text gadget disappeared from ALL pages including the hompage :-(

Shawn C. Parker said...

Placing the code to make the welcome show only on the homepage did not work! And the post editor will not allow 0 posts. The lowest number you can use is 1. Anymore ideas?

Shawn C. Parker said...

I'm sorry it actually did work!...still shows sidebars. Can we do it without showing the sidebars?

Chuck said...

Shawn,

You can suppress the sidebars, using conditional style sheet code. I have that guide in the works.

Ernest said...

thank you. this really helped!

ICU Library said...

Amazing! It did work. Thank you for the guide. It really helps. Though, I didn't use the Text gadget, I just used the HTML/Java Script gadget and followed the guide and inserted the under the widget. Again, thanks!

Quick, Easy and Healthy Recipes

Elizabeth said...

you rock!

jdat747 said...

Awesome, thanks for the incredibly well organized and detailed explanation of how to do all this

.brittney. said...

I posted this question on another part of this tutorial, but it's driving me crazy, so I thought I would post it here, too, just in case...

I wanted to ask you if it's possible to use two conditional codes for one widget/blog element? For example, if I only wanted my labels widget to appear on two static pages and no where else. Is this possible? Thanks ever so!

.brittney. said...

Amazing tutorial, btw! ^_^

Sherab Chen 妙音勝慧 said...

Thank you, N-Buzz (is this your name?) This is exactly what I wanted to achieve. But it has a problem on my blog -- when I click on a Topic, the page will display, in the place of that "Welcome message" a box saying "Showing newest posts with label bibliography. Show older posts" -- How can I make this disappear? It should be either The welcome message or not come up! Thanks,

Robert A. Randolph said...

Great post! I used it and it worked. It was simple and looks good. Thanks.

GnC said...

The conditional statement removes the contents of the gadget, but it does not remove the gadget altogether. There is still a small empty space left, which is also apparent on your own page. If you use a gadget background that is different from the blog background you will see the gadget as a narrow empty block. Is there a way to remove it completely?

rexjhnphotography said...

what if i want an image to stay at top

HELLO said...

I followed your instructions but the welcome test message is still appearing at the top of all my 'pages'. Is there anything I may have overlooked? I've checked and double checked your code that I copied and pasted. Thanks!

nobody said...

Thank you! It really worked!!

vipinlalt said...

Good it worked thanks for this effort.................