Recently at a local Wordpress Users’ Group, I discussed some of our favorite Wordpress Plugins here at T&S Web Design. Check out part 1/3 below, with Contact Form 7. Parts 2 & 3 coming soon…
Our CMS won an award!

Okay, okay, it’s not technically our content management system, per se. But Wordpress, the software that we install on 90% (or more) of our websites so clients can manage their own sites and blog if they so desire, recently won the 2009 Open Source CMS Award.
Wordpress started out as a blogging platform, and we at T&S installed it on dozens of clients sites. The software was constantly improved upon and updated over the months, and eventually developed into a full-fledged content management system. After extensive testing, we began using it for the majority of our clients.
Anyway, congratulations to the Wordpress team, and thanks for providing so many out there with a great CMS.
Display the top level category in Wordpress
The is just a quick Wordpress code snippet for those Wordpress programmers or code dabblers out there.
Recently we needed a page in Wordpress to display the top parent page title rather than the current page’s title as the heading on the page. Here’s the code we used to accomplish that:
<?
$currPost = $post;
while ($currPost->post_parent) {
$currPost = $currPost->post_parent;
}
$title = get_the_title($currPost);
?>
<h2>[ <?php echo $title; ?> ]</h2>
Manipulating Wordpress strings that print directly
Disclosure: This post is for tech-inclined Wordpress users, who like to code, or even do it out of necessity. If that doesn’t interest you at all, or you have no idea what I’m talking about, feel free to ignore this post.
We’re big fans of Wordpress around here. Unfortunately, many of Wordpress’s functions directly print out text and HTML instead of returning a string that can be manipulated directly.
Fortunately, there is a way around that limitation, ob_start. You can feel free to read theĀ documentation of ob_start, but the short version is that it buffers your output temporarily so you can save it as a string and manipulate it before outputting it.
Let’s look at an example. We’ve added some meta data to a post to display some dates and locations on a page. (Click to enlarge)
Now let’s look at the code.
<?php the_meta(); ?>
The above code outputs the following HTML:
<ul class='post-meta'> <li><span class='post-meta-key'>July 14, 2009:</span> Marketing Rxpo</li> <li><span class='post-meta-key'>July 7, 2009:</span> Client Mixer</li> </ul>
We want two changes. First, we don’t want the colon (:) after the date. Second, we want the spans to have a class of Date instead of post-meta-key. With the code as is, Wordpress just displays the info, with no way to change it. So let’s use ob_start instead:
<?php
ob_start();
the_meta();
$out = ob_get_clean();
$out = str_replace(':</span>', '</span>', $out);
$out = str_replace('post-meta-key', 'Date', $out);
echo $out;
?>
Here’s the output we get now:
<ul class='post-meta'> <li><span class='Date'>July 14, 2009</span> Marketing Rxpo</li> <li><span class='Date'>July 7, 2009</span> Client Mixer</li> </ul>
Naturally, any string manipulation that can be done in PHP can be performed, this is just a simple example.
Tags: ob_start, php, string manipulation, strings, wordpress —





