Howdy! This is the personal website of Swedish web developer Pär Thernström. You can contact me directly at par.thernstrom@gmail.com or through Twitter at twitter.com/eskapism/.

Besök arkivet för en lista med alla inlägg.

WordPress: function to format teaser different from body

Skrivet lördag 26 mars, 2011 | Inga kommentarer

On many sites that I develop I want to show articles that contains both a teaser  text and a body text, and I want to be able to format the teaser different than the body. So…I made a function to accomplish this.

What the function does is that it wraps everything in the post before the ”read more”-tag in a div with the class "post-teaser", and everything else in a div with the class "post-body". Then it’s a piece of cake to add som styles to those divs with CSS.

I like it and use it a lot. And here it is:

/**
 * This is a nifty little finction that makes is possible to
 * format teaser and body differently
 *
 * It will output:
 * - teaser/text before the read-more-thingie wrapped in div.post-teaser
 * - body/text after the read-more-thingie wrapped in div.post-body
 * - ..but only if each one exists. so you can get teaser + body, or only teaser, or only body
 *
 * @author Pär Thernström
 *
 */
function ma_teaser_and_body($post_id = NULL) {

 global $post, $more;
 $post_org = $post;
 $more_org = $more;

 if (!$post_id) {
 $post_id = $post->ID;
 }

 $post = get_post($post_id);
 setup_postdata($post);

 // Get teaser/text before the "read me"
 $content = $post->post_content;
 if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
 // more-tag exists
 $more = 0;
 ob_start();
 the_content("", true);
 $teaser = ob_get_clean();
 } else {
 $teaser = "";
 }

 // Get the content/text after "read me"
 $more = 1;
 ob_start();
 the_content(NULL, true);
 $body = ob_get_clean();
 if ($teaser) {
 $teaser = "<div class='post-teaser'>$teaser</div>";
 }

 if ($body) {
 $body = "<div class='post-body'>$body</div>";
 }

 $post = $post_org;
 $more = $more_org;
 setup_postdata($post);
 echo $teaser . $body;

}

Changelog
27 mar 2011: Updated code a bit due to a problem that occured when no more-tag existed in post.

CMS Tree Page View recommended at WordCamp Australia

Skrivet onsdag 09 mars, 2011 | Inga kommentarer

Troy Dean of Video User Manuals did a presentation at WordCamp Australia called ”Better WordPress For Clients”. About 16 minutes in the talk he recommends my WordPress plugin CMS Tree Page View for managing pages in sites with more than 10 pages. Thanks for telling Australia, Troy! :)

Add notes to Gmail and sync with SimpleNote with this Raplet for Rapportive

Skrivet söndag 27 februari, 2011 | 2 kommentarer

Since yesterday I can add notes to all my emails in Gmail. And each note is also stored in SimpleNote, so I have access to each note in Gmail, SimpleNote and in desktop apps like Notational Velocity.

This functionally is something I’ve missed for a long time:

Every day I get emails with for example todos. ”Please fix these 5 things on this website”. Ok, cool. But how do I keep track of my progress in completing the tasks in this email? I used to create a todo-note in SimleNote. Fine. It works. But I loose the connection to the message in Gmail. So I used to paste the URL to the gmail message into the note. Fine. Works too. But what if I am in Gmail and looking at the email? Then I must search SimpleNote to see if I have any notes there for this specific message. Ok, it’s starting to get cumbersome. So I thought that ”Hey, can’t I use the same note in both SimpleNote and Gmail?”. And thanks to Rapportive and it’s Raplet-system it turns out that I actually could.

It’s great btw. Feels like magic. Works like magic.

Some screenshots of the Raplet in action:

The note as it looks in Gmail


…and the same note in the SimpleNote web app


..and the same note in Notational Velocity

WordPress 3.1: more CMS than ever

Skrivet torsdag 24 februari, 2011 | Inga kommentarer

This week has been all about the new WordPress release: 3.1. It is a great release and some of the new features that I really like are the new add link popup that easy let’s you choose among your existing pages and the writing interface that now features a lot less panels than before (something I’ve been bothered by for a long time).

Also, as Matt says: ”With the 3.1 release, WordPress is more of a CMS than ever before”.

These words from Matt feels very good for me since most of my plugins for WordPress focus on extending it’s CMS functionality.

So: WordPress 3.1 + CMS Tree Page View + Simple Fields + Simple History = a heck of a CMS!

Jag har blivit en programköpare

Skrivet torsdag 24 februari, 2011 | Inga kommentarer

Lika bra jag kommer ut ur garderoben: jag har blivit en person som köper datorprogram. Länge har jag hängt på forum och på the pirate bay för att få tag på fulla versioner av program, men efter att jag själv börjat skriva plugins till WordPress så har jag insett att man måste belöna de personer som sliter för att göra något bra.

Själv blir jag överlycklig så fort någon bloggar, twittrar eller donerar pengar till mina projekt och plugins. Så jag kan bara inte vara sämre själv och därför är min policy framöver att allt jag använder regelbundet ska jag betala för eller donera till.

Följande program och tjänster är några av de jag hittills köpt:

« Nyare inläggÄldre inlägg »