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

by Ashwin on September 15, 2009

in Blog Business,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.

Verified to Work with Thesis Theme 1.8! Enjoy!

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.

[css]
/* 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 */ [/css]

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).

[php]
/* Latest Tweets above Content column */
function twitter_before_content() {
if (is_home()) { ?>











}
}
add_action(‘thesis_hook_before_content’, ‘twitter_before_content’);
[/php]
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 @thotsunlimited or in case you face any issues with setting this up on your Thesis Blog. I would love to help!

{ 38 comments… read them below or add one }

Matt Langford September 17, 2009 at 12:27 am

Nice tut! I especially like the highlighted tweet from some dude named @Matt425!

Reply

Ashwin / Thoughts Unlimited September 17, 2009 at 1:00 am

Thanks Matt! Yeah @Matt425 is a cool friend of mine =)

Reply

Avinash d'Souza October 4, 2009 at 3:11 pm

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….

Reply

Ashwin / Thoughts Unlimited October 5, 2009 at 3:05 am

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.

Reply

Avinash d'Souza October 5, 2009 at 4:35 pm

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…

Reply

Ashwin / Thoughts Unlimited October 6, 2009 at 9:43 am

For showing the 'Join' link on the same line as the time (or days) – use the following:

/custom/images/tipicon-medium.jpg” align=”left” style=”border:none;vertical-align:center;” width=”30″ height=”45″/>
Have a Tip for all Bloggers and Social Media Users out there? /contact”>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…

Reply

Ashwin / Thoughts Unlimited October 6, 2009 at 9:44 am

You can apply background and the border styles to the CSS element:

#twitter_div

This will spruce up your Twitter box!

Reply

John October 21, 2009 at 1:33 am

I followed this code exactly and it works in Firefox 3, but breaks my homepage in IE8.

Any ideas?

Reply

Ashwin / Thoughts Unlimited October 21, 2009 at 2:03 am

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.

Reply

John October 21, 2009 at 2:24 am

thanks. fyi, I am running your tut on Thesis 1.6 which was just released today.

Reply

John October 21, 2009 at 9:47 pm

Hi Ashwin… any luck?

Reply

Ashwin / Thoughts Unlimited October 21, 2009 at 11:16 pm

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

I am still looking to find a workaround… Will let you know once I have something

Reply

John October 22, 2009 at 6:51 pm

Thanks for looking into it, glad it's not my imagination. Hope you figure it out soon, this is an awesome mod.

Reply

Ashwin / Thoughts Unlimited October 23, 2009 at 12:40 am

Thanks John. I will surely let you know if I solve the problem :)

Reply

Alexandru October 23, 2009 at 4:00 am

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

Reply

Ashwin / Thoughts Unlimited October 23, 2009 at 4:42 am

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…

Reply

John October 30, 2009 at 8:59 pm

any luck?

Reply

John October 30, 2009 at 9:32 pm

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?

Reply

Ashwin / Thoughts Unlimited October 31, 2009 at 2:12 pm

Yes even i found that the issue is with Javascript. Refer to the my earlier chain of comments:

- Problem is caused by

So this API is out of our hands! :(

Reply

juanbravo November 20, 2009 at 1:06 am

hey man, how to add some gray background here? thank you..

Reply

Ashwin / Thoughts Unlimited November 20, 2009 at 2:21 am

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.

Reply

juanbravo November 20, 2009 at 9:42 am

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

Reply

shamrock December 1, 2009 at 2:45 am

Can I run this in a exec php widget on wordpress?

Reply

Ashwin / Thoughts Unlimited December 3, 2009 at 7:46 am

Yes in Theory you should be able to do it. Let me know if it did not work.

Reply

Ashwin / Thoughts Unlimited December 3, 2009 at 6:16 pm

Yes in Theory you should be able to do it. Let me know if it did not work.

Reply

manavecplan March 17, 2010 at 4:01 pm

Hi Ashwin,

Quick question here…what would be the css to move the day count (eg. 14 mins ago) to the same line as the status? Thnx…

Reply

Ashwin / Thoughts Unlimited March 18, 2010 at 2:34 am

The link you specific actually comes from Twitter API.

The best I think is to tweak with this CSS.

#twitter_div li span a { … }

I don't have the exact code yet – but a float:right; and a top negative margin should help.
Let me know if it works.

Thanks.

Reply

manavecplan March 18, 2010 at 8:34 pm

Nope…that didn't quite work out. :-(

Reply

Ashwin / Thoughts Unlimited March 19, 2010 at 2:07 pm

Let me try it this weekend on my sandbox and let you know. Thanks.

Reply

manavecplan March 19, 2010 at 8:59 pm

Thanx a ton Ashwin…much appreciated as always!

Reply

Rodelio Lagahit April 20, 2010 at 5:08 am

after loading the codes in the custom_functions I got this error “Parse error: syntax error, unexpected '?' in /home7/diwanagc/public_html/jobgrand/wp-content/themes/thesis_17/custom/custom_functions.php on line 34″

what did i miss? just copied the code and edit only ***yourtwitter*** nothing more nothing less…

Reply

Ashwin April 21, 2010 at 1:23 am

@Rodelio

Can you try this code instead? The code in the post has some character escapes, which are removed here…

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












}
}
add_action('thesis_hook_before_content', 'my_thesis_before_content');

Reply

Rodelio Lagahit April 22, 2010 at 6:25 am

Thanks! worked like a charm.. but gotta catch the twitter bird coz it's missing.. :) once again, thank you!

Reply

Max May 6, 2010 at 9:06 am

Hey Ashhwin,

For some reason, all I see is the half Twitter bird and no tweet. Can you please let me know what the problem might be?

Reply

Ashwin May 8, 2010 at 1:11 am

Max,

Whenever the Twitter API down or non-responsive – and there is no tweet to show – only half of the Twitter bird is shown…

Can you check if this happens all the time?

Reply

Puppies for Sale May 21, 2010 at 2:05 am

As a new user of Twitter, this tutorial will help me a lot. I will surely follow your instructions.

Reply

rys July 13, 2010 at 6:30 am

you can also refer to this site on how to display your latest tweets using twitter API
as easy as 1 2 3..

http://www.ryscript.co.cc/web/how-to-display-la...

thanks

Reply

Jorge Ledesma September 11, 2010 at 3:33 am

Just tried it again, simply copy and paste into custom.php and not working FYI, thanks looking forward to see it working

Reply

Cancel reply

Leave a Comment

CommentLuv Enabled

{ 10 trackbacks }

  • Ashwin
  • Ashwin
  • Ashwin
  • WordPress wptop50.de
  • Ashwin
  • Show your latest Tweet on top of Content Column in Thesis Theme — Thesis Press Visual Guides
  • Michael Totten
  • yamasas
  • 47 Customizations for the Thesis Theme
  • Ashwin

Previous post:

Next post: