Mostly about my amusement

Tag: WordPress (page 10 of 13)

Widgetized my theme

In preparation of installing WordPress 2.5 I finally widgetized my theme. I’m using an old 2.0 version of FastTrack. Widgets have been around for a long time so as I play with 2.5 I figured I’d come up to speed with a 2.0 feature.

I had a bunch of nested if..thens so that the home page would show one sidebar and single posts and pages would show another. I had cleaned up the theme so I now had separated the two sidebars in the file.

In my theme’s function.php I added the following lines:

if ( function_exists(’register_sidebar’) )
register_sidebars(2,array(
‘before_widget’ => ”,
‘after_widget’ => ”,
‘before_title’ => ‘<h2>’,
‘after_title’ => ‘</h2>’,
));

This let me define 2 sidebars, one for the home page and one for not the home page.

In my sidebar.php I placed

php code for the is_home() sidebar

<?php endif; ?>

<?php } else { ?>

<?php if ( !function_exists(’dynamic_sidebar’) || !dynamic_sidebar(2) ) : ?>

php code for the all other pages sidebar

<?php endif; ?>

<?php }?>

This let me have a default for each sidebar. That’s where I ran into a snag. I want to re-use the same widgets in both sidebars. The widgets won’t let me use them twice. I wanted to use the meta widget on the home page as well as on the single posts.

If I want I can define additional duplicate widgets but that’s a pain. I’m playing with the idea of defining a third dynamic sidebar and display that on the bottom of each sidebar.

I’ll keep playing with it to find a solution I like.

Playing with WordPress 2.5 beta

I keep a SVN based copy of the new WordPress 2.5-beta1 for playing with. I’m doing this because at sometime the version I’m running 2.3.x might not be supported for patches. Going from 2.2 to 2.3 was a no brainer, tags are a huge difference. 2.5 might not get me to jump for a while.

On the outside I can’t see much reason for not converting. Some of my plugins don’t work but that ought to be resolved by the time 2.5 is released. If the performance is improved then that’s a good reason right there.

What will get me to hold off is the little things. I dislike the new interface. The 2.3.x shows it’s age meaning that it is well thought out and is missing some pet peeves from 1.5 or 2.0. Version 2.5 feels like they are trying to get to “Web 2.0” and are not making it. The organization is odd after using WordPress for a couple of years. The widget interface is downright counter intuitive for me.

I’ll keep using 2.3.x for a while and just see how 2.5 turns out.

Movable Type to WordPress

Over at my brother Stefan’s blog, he’s been running Movable Type for years. It bugged be because his server was slow, the theme was dated, it lacked a good archive page, etc.

Mostly I did not like the look or the speed. Stefan takes really good pictures and I thought he should have a web site that can show off some of his work. What I ended up showing him was good enough that he told me to go ahead and do it.

Read on for what I had to do to make it all work. Read more

Okay I think I got ATPP working

I think I’ve gotten the machine translation working to a point of good stability. Meaning my MySQL config is not killing the box with requests, caching seems to be working fine.

Right now I have 65 translated pages in my database. When I encounter one that is munged (meaning the database timed out) I manually delete that page in the ATPP cache and only that page. So fare so good.

I combined ATPP with WP-CACHE and all seems right in the world.

Fun with WordPress tags

Going from UTW to WordPress 2.3’s built in tag system was mostly painless. But there are somethings I miss about UTW. Two of those things are being able to display “Tags: None” and having my tags show up in my RSS feeds. Here is how I was able to put both back into my blog.

Adding “Tags: None” to my theme

I’m not a PHP programmer. I had thought I could just do $my_tags=the_tags(); and put in an if..then loop to check if it’s empty. That did not work; referencing the_tags() would cause the output to go to the $content and get displayed.

PHP has a function called ob_start(). From the manual page:

This function will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer.

That’s good! Looking around some more I saw that using ob_get_clean() can put that buffer into my variable. That’s what I wanted so I could just capture and test the output. Here is the code I put into my theme template.

<?php if (function_exists(‘the_tags’)) {
ob_start();
the_tags();
$my_tags = ob_get_clean();
if ( $my_tags != “” ) {
echo $my_tags;
} else {
echo “Tags: None”;
}
} ?>

This lets me check the output from the tags and if it is empty then I can display “Tags: None” when I want.

Update: There is an easier way without using ob_start(), using get_the_tags().

<?php if (function_exists(‘the_tags’)) {
$my_tags = get_the_tags();
if ( $my_tags != “” ) {
the_tags();
} else {
echo “Tags: None”;
}
} ?>

I thought about this because a) it’s easier, and b) I think that wp-cache might do this and then my theme might cause issues.

Adding tags to my feeds

Making feed include tags was a simple matter as well. I had read on Angsuman’s blog about a plugin that lets you append copyright notices to your feeds. I downloaded it and took a look at the plugin. Simplest code in the world, I just modified Angsuman’s plugin. Here is what it looks like.

<?php
/*
Plugin Name: Add Tags to Feeds
Plugin URI:
Description: This adds WP 2.3 tags to your feeds.
Author: Jan Dembowski
Author URI:
Version: 1.0
*/

function addTagsToFeed($content) {
global $my_tags;
ob_start();
the_tags();
$my_tags = ob_get_clean();
if(is_feed()) {
return $content.”<p class=”tags”>”.$my_tags.”</p>”;
} else {
return $content;
}
}
add_filter(‘the_content’, ‘addTagsToFeed’);
?>

Nothing to it. My feed validates and now the tags are in the feeds too. Seeing how existing code uses add_filter is probably the best way to learn by example.

Getting ready for WordPress 2.3

In a few days the new version of WordPress comes out and with the exception of tags, for me the upgrade to 2.3 is pretty straight forward.

I have to plan to stop using UTW and switch to the built in tag system. I also want to make sure that I can fall back to 2.2.3 if the “bad thing” happens.

I like to mix tags with Share This on the same line, seperated by a “|”. On my blog I currently have the following lines in my theme:

  1. <div class=”utwtags”>
  2. <?php if (function_exists(‘akst_share_link’)) : ?> <?php akst_share_link(); ?><?php endif; ?>
  3. <?php if (function_exists(‘akst_share_link’) and function_exists(‘UTW_ShowTagsForCurrentPost’)) : ?> <?php _e(‘ | ‘); ?> <?php endif; ?>
  4. <?php if (function_exists(‘UTW_ShowTagsForCurrentPost’)) : ?><?php _e(‘Tags: ‘); ?><?php UTW_ShowTagsForCurrentPost(“commalist”) ?><?php endif; ?>
  5. </div><p />

I am the king of Ugly Code(tm). Someday I will re-write the theme to make it readable and organized. I repeat the same code in 4 different files.

In WordPress 2.3 the_tags() function is available. I want to be able to roll back to UTW and 2.2.3 so I add some if..thens to check for the_tags(). I will have UTW disabled with 2.3 and the inserted code is in bold below on lines 3 and 5.

  1. <div class=”utwtags”>
  2. <?php if (function_exists(‘akst_share_link’)) : ?> <?php akst_share_link(); ?><?php endif; ?>
  3. <?php if (function_exists(‘akst_share_link’) and (function_exists(‘UTW_ShowTagsForCurrentPost’) or function_exists(‘the_tags’))) : ?> <?php _e(‘ | ‘); ?> <?php endif; ?>
  4. <?php if (function_exists(‘UTW_ShowTagsForCurrentPost’)) : ?><?php _e(‘Tags: ‘); ?><?php UTW_ShowTagsForCurrentPost(“commalist”) ?><?php endif; ?>
  5. <?php if (function_exists(‘the_tags’)) : ?><?php the_tags(); ?><?php endif; ?>
  6. </div><p />

For my archive template I have a tag cloud using this code.

  1. <?php if (function_exists(‘UTW_ShowWeightedTagSet’)) { ?>
  2. <p>Tags:</p>
  3. <div class=”utwtag-cloud”>
  4. <?php UTW_ShowWeightedTagSetAlphabetical(“coloredsizedtagcloudwithcount”,””,0); ?></p>
  5. </div>
  6. <?php } ?>

The </p> at the end of line 4 is because the UTW function leaves out the closing </p> and messes up validation (I have no idea why). This code is fine and can stay. I just insert code underneath just like it as so

  1. <?php if (function_exists(‘wp_tag_cloud’)) { ?>
  2. <p>Tags:</p>
  3. <div class=”tag-cloud”>
  4. <?php wp_tag_cloud(‘number=300’); ?>
  5. </div>
  6. <?php } ?>

The default number of tags is 45. That shows the 45 most used tags; I just put 300 (way more than I use) to keep it on par with the existing tag cloud and display all the tags I have.

The UTW importer in 2.3 is pretty good but it adds a hyphen where a space should be. So “Far Cry” becomes “Far-Cry”. This is in the tag label and originally I was going to play with the dump of my database, modify tags by hand and hope for the best. WordPress 2.3 has no built in tag management system.

Rather than start that brain surgery I lucked out. Poplarware provides the Advanced Tag Entry plugin which lets you modify and manage your WordPress tags from the write post page on your blog. My only minor complaint is that the plugin does not also live under the Manage section. Using this plugin let me edit and fix the space issue on my tags. Going forward I’ll use this plugin to select the tags I want to re-use.

Christine (the UTW author) put together a good plugin for using Yahoo’s API to obtain tag suggestions. It’s called Tag Suggest Thing and it uses Yahoo to get suggested tags for your post. You can click on the tags one at a time or add all. Very useful.

With the exception of one plugin (which I don’t really use) all my plugins work with 2.3-RC1. This is all tested on my backup blog and with these changes and getting two new plugins, I should be ready for 2.3 without any hitch.

Akismet Auntie-Spam Greasemonkey Script

Hey I was useful finding and fixing a bug 🙂

Engtech’s Auntie-Spam greasemonkey script was loading the Akismet pages using xmlhttprequest to load all of the SPAM pages into one condensed page for digestion which is very cool. And for for non-SSL admin pages works flawlessly.

I use the Admin SSL plugin on my WordPress blogs. The xmlhttprequest does not like loading https:// urls. The technical description is “it borks”.

I found an easy way to modify the URL’s being loaded. After putting in one line to make the script only load the http version of the pages I sent the fix and Engtech updated his script.

It’s a really well done greasemonkey script and if you use Akismet and Firefox get that installed right away. And if you run into a problem, work with Engtech on it. He doesn’t waste any time fixing bugs once he finds it.

WordPress 2.3 beta tag cloud

The WordPress 2.3 beta tag cloud is XHTML Transitional not Strict.  Also if you want to keep UTW then the permalinks /tag/sometag will not work; the /tag/ will go to the WordPress one and not the UTW version.

Hopefully someone will make a UTW like interface, presentation plugin that lets you use the built-in tag system but enjoy UTW’s tools and functions.