Show your latest Tweet on top of Content Column in Thesis Theme

by Ashwin on September 15, 2009

in Thesis Tips, Wordpress

Thesis Theme makes life a lot simpler, if you are trying to customize your blog.  In this post, I will show you how to display your latest tweets at the top of your content column.  You can either choose to display this only on the Home page or on all pages.

What we will Create?

This is what we are trying to create in this tutorial – the latest twitter update on the top of your content column.  There is also a link to your Twitter profile home page.

thesistwittertop_1


How do we get this?

As with any other customization in Thesis Theme, this requires changes in the following files found under the //custom folder.

  • custom_functions.php
  • custom.css

Changes in custom.css

Copy the following code into your custom.css file towards the bottom.  I have suitably demarcated the code with a comment, so that you can easily identify it later.

/* Twitter widget Before content */
#twitter_div {
  background:transparent url(images/twitter_verysmall.gif) no-repeat scroll 0 10px;
  padding:10px 0 10px 48px; position:relative;
}
#twitter_div li {
  font-family:georgia,serif;
  font-size:1em;
  font-size-adjust:none;
  font-stretch:normal;
  font-style:normal;
  font-variant:normal;
  font-weight:normal;
  line-height:normal;
  list-style-image:none;
  list-style-position:outside;
  list-style-type:none;
}
#twitter_div li span {
  display:block;
  font-size:1.1em;
  font-style:italic;
}
#twitter_div ul {
  margin:0 0 8px 12px;
}
#twitter_div li span a a:visited {
  color:#2A69A3; text-decoration:none;
}
#twitter_link {
  color:#2A69A3;
  text-decoration:none;
  font-size:1em;
  font-style:italic;
  float:right;
  margin-right:25px;
}
/* Twitter widget Before content */ 

I have used a very small Twitter icon that displays on the left corner.  You can download the icon from here (right click and ‘Save as’).

twitter_verysmall

Copy this file into your //custom/images folder.

Changes in custom_functions.php

Now copy the following code into your custom_functions.php file.  This code uses the ‘thesis_hook_before_content’ of Thesis.  So if you are already using this Hook in your Thesis Customization, just add only the HTML portion of this code towards the end (if you have any problems, feel free to contact me).

/* Latest Tweets above Content column */
function my_thesis_before_content() {
  if (is_home()) { ?>
   

In the above code, there are a couple of points where it is mentioned as **yourtwitter**. Replace them with your Twitter username.

Current Code as is, would display the Twitter updates only on your home page. If you want this to be displayed on all other pages and posts, just remove the following

  • if (is_home()) from the top
  • } from the bottom

Tip: For the sake of this tutorial, I have used the thesis_hook_before_content hook. But you can easily replace with other hooks like thesis_hook_before_post_box, thesis_hook_before_post, thesis_hook_after_post, thesis_hook_after_post_box, etc., depending on where you need the Twitter updates to appear. Love the power of Thesis!

Conclusion

And, that’s it. Now just reload your page and see your latest tweet right there at the top. Contact me @tublogger or in case you face any issues with setting this up on your Thesis Blog. I would love to help!

  1. Search Box in Navigation Bar of the Thesis Theme
  2. Control Home Page Post Excerpt Content in Thesis Theme
  3. Thesis Theme : Setup Pagination on Home Page
  4. Create a Killer Services and Portfolio Page with Thesis Theme
  5. Setup a Header Banner Image for your blog using Thesis Theme

Stay In The Loop!

 Subscribe to our RSS Feed
 Join on Twitter
 Get Posts via Email

  • Matt Langford
    Nice tut! I especially like the highlighted tweet from some dude named @Matt425!
  • Thanks Matt! Yeah @Matt425 is a cool friend of mine =)
  • Avinash d'Souza
    This doesn;t seem to be working for me Ashwin...the gif just refuses to show up. Also, the formatting isn't kicking in like on your blog....
  • Avinash,

    A couple of questions - are you using the code as is or done some changes. If yes, can you send me the code that you use.

    Also a link to your Blog would be appreciated. Let me just take a look.
  • Avinash d'Souza
    Very strange...but it works like a charm now. Probably because I deleted all the other code... :-)

    Need a bit of help in styling though...need the "Join me on Twitter" link on the same line as the number of days. Firebug testinf isn't letting me move the twitter link div up past a point.

    Also, is there anyway of giving the entire widget a background and a border?

    Still in sandbox mode so no link...
  • For showing the 'Join' link on the same line as the time (or days) - use the following:






    Have a Tip for all Bloggers and Social Media Users out there? Contribute and be featured on the sidebar of this Blog (with a do-follow link to your Blog/Website of course!)












    and the CSS:

    #twitter_link_new {
    color:#2A69A3;
    text-decoration:none;
    font-size:1em;
    font-style:italic;
    float:right;
    margin-top:-15px;
    padding-right:20px;
    }

    Actually negative margin will do the trick...
  • You can apply background and the border styles to the CSS element:

    #twitter_div

    This will spruce up your Twitter box!
  • John
    I followed this code exactly and it works in Firefox 3, but breaks my homepage in IE8.

    Any ideas?
  • Hi John,

    Thanks for letting me know. I will check it later in the day on IE8 and let you know is something needs a change.
  • John
    thanks. fyi, I am running your tut on Thesis 1.6 which was just released today.
  • John
    Hi Ashwin... any luck?
  • Hi John,

    No complete solution yet - I had set it up on my sandbox site - https://thoughtsunlimited.net/apps/sandbox/

    Works good on FF, Safari and Chrome and older IE. Breaks only on IE8. Few observations:
    - Problem is caused by
  • John
    Thanks for looking into it, glad it's not my imagination. Hope you figure it out soon, this is an awesome mod.
  • Thanks John. I will surely let you know if I solve the problem :)
  • John
    any luck?
  • John
    fyi, if I remove from the custom functions and then reload, it does not break IE8, but it is not showing the tweet. So it has to be related to that java code, yes?
  • Yes even i found that the issue is with Javascript. Refer to the my earlier chain of comments:

    - Problem is caused by
  • Alexandru
    Hy!

    How can i actually show this on another page other than home.Let's say about page?
    Replacing if (is_home()) with what?

    tks
  • Hi Alexandru,

    To display on Single Posts (and not home page) - if (is_single())

    To display on all Pages (non Posts) - if(is_page())

    To display on specific Page - if(is_page('2'))

    Here '2' is the Page id. You can go to WP Dashboard->Pages and hover the mouse over the Page name. On the status bar you can see the Page id there.

    To use a combination - show in Single Posts and Page with id=2,

    if (is_single() || is_page('2'))

    This also would work.

    Let me know if you want to know more...
  • juanbravo
    hey man, how to add some gray background here? thank you..
  • You should be able to do it - by tweaking the '#twitter_div' CSS element.

    right now the background element is:

    background:transparent url(images/twitter_verysmall.gif) no-repeat scroll 0 10px;

    here you should be able to replace 'transparent' with the 'hex color code' to get the background.

    Let me know if it works.
  • juanbravo
    that's working, but the link to subscribe is not had the background...
    i want the link to subscribe is also have the same background.. thank you before
  • shamrock
    Can I run this in a exec php widget on wordpress?
  • Yes in Theory you should be able to do it. Let me know if it did not work.
blog comments powered by Disqus

Previous post:

Next post: