Archive for the 'Programming' Category

Fix 404 errors on Ultimate Tag Warrior

Monday, February 19th, 2007

I uses Ultimate Tag Warrior version 3.14159265 (February 4th, 2007) with WordPress 2.1, it work great but there have some problem or bug that when you try to open /tag it will show 404 errors. I check and try to make the page /tag or /tag/ show all tags with function of Ultimate Tag Warrior. Here is small changed.

PHP:
  1. function ultimate_tag_templates() {
  2.     if ($_GET["archive"] == "tag") {
  3.         include(TEMPLATEPATH . '/tag_all.php');
  4.         exit;
  5.     } else  if (get_query_var("tag") != "") {
  6.         ultimate_get_posts();
  7.  
  8.         if (is_feed()) {
  9.  
  10.             return;
  11.         }
  12.         if (file_exists(TEMPLATEPATH . "/tag.php")) {
  13.             if ( $_GET["feed"] == '') {
  14.                 include(TEMPLATEPATH . '/tag.php');
  15.                 exit;
  16.             }
  17.         } else {
  18.     //    include(TEMPLATEPATH . '/index.php');
  19.         }
  20.     }
  21. }

This function will process when you query for tag but you will see if you request with empty value of tag it won’t process anything and let Wordpress process this and finally it give 404 errors

I just made some changes to handle when user query with empty tag or open at /tag or /tag/

PHP:
  1. function ultimate_tag_templates() {
  2.     if ($_GET["archive"] == "tag") {
  3.         include(TEMPLATEPATH . '/tag_all.php');
  4.         exit;
  5.     } else  if (get_query_var("tag") != "") {
  6.         ultimate_get_posts();
  7.  
  8.         if (is_feed()) {
  9.  
  10.             return;
  11.         }
  12.         if (file_exists(TEMPLATEPATH . "/tag.php")) {
  13.             if ( $_GET["feed"] == '') {
  14.                 include(TEMPLATEPATH . '/tag.php');
  15.                 exit;
  16.             }
  17.         } else {
  18.     //    include(TEMPLATEPATH . '/index.php');
  19.         } else    {  
  20.         if ( (eregi('^/tag$', $_SERVER['REQUEST_URI']) ) ||
  21. (eregi("^/tag/$", $_SERVER['REQUEST_URI'])) ) {  
  22.         include(TEMPLATEPATH . '/tags.php');
  23.         exit;
  24.         }
  25.     }
  26. }

You may need to have file tags.php in your theme directory

Here is example of tags.php

PHP:
  1. <?php get_header(); ?>
  2.  
  3. <div class="primary">
  4.  
  5.     <?php UTW_ShowWeightedTagSetAlphabetical("coloredsizedtagcloud","",0) ?>
  6.  
  7. </div>
  8.  
  9. <?php get_sidebar(); ?>
  10.  
  11. <?php get_footer(); ?>

You also can change function or parameters to display tag in the page as you want. Please see all detail here UltimateTagWarrior help

Change category name without 404 errors

Friday, February 16th, 2007

Today I try to change category name from anti-virus to virus but using old permalink /%category%/%postname%.html and i found later that there have 404 errors. I try to looking around on search engine but could not find any mod_rewrite to fix this problem. Finally I look into source code of Wordpress 2.1 and change the code below:-

/wp-includes/category.php

Search for line 168

function get_category_by_path($category_path, $full_match = true, $output = OBJECT) {

Add this code after global $wpdb;

$category_path = str_replace('old-category', 'new-category', $category_path);

For above I changed my /wp-includes/category.php to

......
function get_category_by_path($category_path, $full_match = true, $output = OBJECT) {
	global $wpdb;
	$category_path = str_replace('anti-virus', 'virus', $category_path);
......

Online tool to help programmer deal with messy php code

Wednesday, February 7th, 2007

Today, I try to search program to make my php source code for better read and easy to understand and I found good one that I would like to suggest for all php programmer.

Online source code beautifier

This tool source code beautifier (source code formatter) also work with Java, C++, C, Perl, JavaScript, CSS code.