Sep
6th

Wordpress Hack: After the First Post only on the Home Page

You’ll note on after the first page after the first post on my home page that I’ve added a Blaugh cartoon. I had one heck of a time figuring out how to simply show the cartoon in one single place on the site without pushing it into the sidebar where it didn’t belong. So… I did some digging and found a couple of themes that utilize some code to do just this. The code could be used to highlight or indicate your latest post… or simply add some content within the WordPress loop.

Here’s how you can do it:

<?php if(is_home() && $post==$posts[0] && !is_paged()) { ?>

Your Content that you want here!
<?php } ?>

For the Blaugh cartoon:

<?php if(is_home() && $post==$posts[0] && !is_paged()) { ?>

<center><script language="Javascript" type="text/javascript" src="http://blaugh.com/latest.php?s=400"></script></center>

<?php } ?>

There you go! Just make sure that you put this content within the loop. I put it right before this line, so I can keep track of it:

<?php endwhile; else: ?>

RSS feed | Trackback URI

11 Comments »

Comment by no imageJohn Pozadzides (SezWho)
2007-07-12 22:07:58

Douglas,

I just wanted to drop you a quick thank you for this tip. I had written an article with a slightly different method that was less effective than yours and one of my readers pointed out your article to me.

I have since modified my article and given credit where credit is due.

Thanks again,

John

Rate this:
2.8
Comment by no imageDouglas Karr (SezWho)
2007-07-15 09:37:06

Thanks John! As well, this was a nice reminder… I had removed the bLaugh a few layouts ago and never put it back. Until today!
Rate this:
2.9
 
 
2007-07-31 05:57:50

[...] loop: EDIT: Thanks to Storm for dropping me a comment with an even simpler method which came from Douglas Karr. Here it is: <?php if(is_home() && $post==$posts[0] && !is_paged()) { ?> [...]
 
Pingback by Sunshine Cake «
2007-09-13 15:24:32

[...] <?php if(is_home() && $post==$posts[0] && !is_paged()) { ?>      <script type=”text/javascript”><!– [...]
 
 
Comment by no imagekanute (SezWho)
2007-11-06 18:30:18

You saved me alot of time, I was just about to start tweeking the loop when I saw this post, I’m really grateful. thanks for sharing it.
Rate this:
1.6
 
Comment by no imageTyler (SezWho)
2008-01-30 16:32:35

Can I implement this code in the sidebar so that the ads only appear in the sidebar on the homepage?
If not, can you please enlighten me on how I can do this?
Thank you!
Tyler
Rate this:
1.6
 
Comment by no imageStever (SezWho)
2008-02-22 14:59:49

To get this code to work over in the sidebar, or anywhere outside of the while loop, just remove all the stuff about $post and $page from the code so you just have this;

stuff goes here

Rate this:
1.6
 
Comment by no imageChris (SezWho)
2008-04-12 12:40:30

Top stuff - thanks for sharing this, it’s a very handy bit of code!
Rate this:
1.6
 
Comment by no imageCody McKibben (SezWho)
2008-06-28 02:36:31

Holy cripe, Doug, you just saved my life. I’ve been looking for that if(is_home() && !is_paged()) solution for hours now! Thank you :)
Rate this:
2.9
Comment by no imageDouglas Karr (SezWho)
2008-06-29 05:07:11

You’re welcome, Cody! That’s why I put this stuff up there. :)
Rate this:
2.9
 
 
Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.

My Comment Policy: I moderate comments. Please be patient:

  • Spam will happily be destroyed.
  • Use your real name, not some keywords. Otherwise it will be destroyed.
  • Mean comments aren't necessary. If I don't post them I will reply personally to let you know why.
  • Lewd comments will be edited, I don't want my readers leaving because of offensive content.
Great debate, criticism and colorful commentary is always appreciated and approved!