Category Archives: Wordpress

Custom Category Templates on a Archive or Index page.

April 23, 2008 by aaron
On my home page and in my archives, I use a custom category template to display asides and news articles. This is very easy to do and it only takes a couple seconds of work to create custom category templates in any WordPress theme. The first step is to add the following to your current theme’s index.php loop after the line that looks like <?php while (have_posts()) : the_post(); ?>, but before any other code.
Read More ⟶

Displaying WordPress categories in a horizontal dropdown menu.

April 16, 2008 by aaron
One of my readers recently asked how I created my horizontal menu bar: the short answer is by mixing CSS and Javascript. The first step is to get WordPress to display the menu as a hierarchical list without a title. <?php wp_list_categories('sort_column=name&sort_order=asc&style=list&children=true&hierarchical=true&title_li=0'); ?> We then wrap this WordPress code in the following so we can style it. <div style="text-align:center;"> <ul id="menu" style="padding:0; margin:0;"> <?php wp_list_categories(&#039;sort_column=name&sort_order=asc&style=list&children=true&hierarchical=true&title_li=0&#039;); ?> </ul> </div> I added this to my header.php, but you can add it anywhere you want it to appear.
Read More ⟶

Mysql Search and Replace.

April 31, 2007 by aaron
I’ve been getting ready for WordPress 2.3, so in preparation I’ve started cleaning up my database. My first order of business was to clean up the tags database. Over time I’ve used several different methods of separating words: all spaces, hyphens and underscores have all been used which really makes the nice names ugly. Fixing this was easy, I just used the MYSQL replace command: UPDATE table SET field =
Read More ⟶

Trapping WordPress errors with output buffering.

April 15, 2007 by aaron
If you have tried to use AJAX with WordPress, most likely you have stumbled upon the wp_die() function which completely kills the response you expect to get. However, we can trap the wp_die() by using PHP’s output buffering and the ob_start callback function to process the output of wp_die() even though a die() is called. This is a very special case, and will only work when you are able to ensure output buffering can be called before the die is called.
Read More ⟶

WordPress 2.3 is looking good.

April 31, 2007 by aaron
I’ve been playing around with WordPress 2.3 Alpha and so far I like it. Good Things: I like the new post status “Pending Review” and the ability to sort posts by status. Somone posted pictures here. Tags are looking good.. A UTW tag importer is built in; of course, I realized this only after I created one. The “categories” database tables have been retired and everything is tag based (categories are a type of tag similar to the ways pages are just a form of post).
Read More ⟶

Improvements for Stattraq plugin.

April 29, 2007 by aaron
Ever since I originally started using Stattraq a few things bothered me about the way it worked. Here are the fixes to a few of them. Include pages with posts in your stats. Open stattraq.php Find: global $doing_rss, $p Replace With: global $doing_rss, $p, $page_id, $pagename, Find: if (($p != &#039;&#039;)){ $p = intval($p); $article_id = $p; } Replace with: if (($p != &#039;&#039;)){ $p = intval($p); $article_id = $p; }elseif (($page_id != &#039;&#039;)){ $page_id = intval($page_id); $article_id = $page_id; }elseif (($pagename != &#039;&#039;)){ $reqpage = get_page_by_path($pagename); if ( !empty($reqpage) ) $article_id = $reqpage->ID; } To add a list of all Pages that link to your site grouped by Website (excluding Google): Open “wp-stattraq/reporter/summary.php” Find: <?php echo PrintTimestamp();?> </div> <div id="queryTerms"> Before Add: <table id="referrersTable"> <thead> <tr> <th>#</th> <th>Referrer</th> <th>Pages</th> </tr> </thead> <tfoot> <tr> <th>#</th> <th>Referrer</th> <th>Pages</th> </tr> </tfoot> <tbody> <?php if($results){ $i=0; foreach($results as $row){ preg_match(&#039;/(http.*?\:\/\/.*?)(\/.*)/&#039;, htmlentities($row->ref), $matches); $ref_array[$matches[1]][] = $matches[2]; } while( list($site, $pages) = @each($ref_array) ){ if(strpos($site,&#039;google&#039;) ==false && $site != &#039;&#039;){?> <tr class="<?php echo ($i % 2 == 0 ?
Read More ⟶

Custom Category Templates on a Archive or Index page.

April 23, 2008 by aaron
On my home page and in my archives, I use a custom category template to display asides and news articles. This is very easy to do and it only takes a couple seconds of work to create custom category templates in any WordPress theme. The first step is to add the following to your current theme’s index.php loop after the line that looks like <?php while (have_posts()) : the_post(); ?>, but before any other code.
Read More ⟶

Displaying WordPress categories in a horizontal dropdown menu.

April 16, 2008 by aaron
One of my readers recently asked how I created my horizontal menu bar: the short answer is by mixing CSS and Javascript. The first step is to get WordPress to display the menu as a hierarchical list without a title. <?php wp_list_categories('sort_column=name&sort_order=asc&style=list&children=true&hierarchical=true&title_li=0'); ?> We then wrap this WordPress code in the following so we can style it. <div style="text-align:center;"> <ul id="menu" style="padding:0; margin:0;"> <?php wp_list_categories(&#039;sort_column=name&sort_order=asc&style=list&children=true&hierarchical=true&title_li=0&#039;); ?> </ul> </div> I added this to my header.php, but you can add it anywhere you want it to appear.
Read More ⟶

Mysql Search and Replace.

April 31, 2007 by aaron
I’ve been getting ready for WordPress 2.3, so in preparation I’ve started cleaning up my database. My first order of business was to clean up the tags database. Over time I’ve used several different methods of separating words: all spaces, hyphens and underscores have all been used which really makes the nice names ugly. Fixing this was easy, I just used the MYSQL replace command: UPDATE table SET field =
Read More ⟶

Trapping WordPress errors with output buffering.

April 15, 2007 by aaron
If you have tried to use AJAX with WordPress, most likely you have stumbled upon the wp_die() function which completely kills the response you expect to get. However, we can trap the wp_die() by using PHP’s output buffering and the ob_start callback function to process the output of wp_die() even though a die() is called. This is a very special case, and will only work when you are able to ensure output buffering can be called before the die is called.
Read More ⟶

WordPress 2.3 is looking good.

April 31, 2007 by aaron
I’ve been playing around with WordPress 2.3 Alpha and so far I like it. Good Things: I like the new post status “Pending Review” and the ability to sort posts by status. Somone posted pictures here. Tags are looking good.. A UTW tag importer is built in; of course, I realized this only after I created one. The “categories” database tables have been retired and everything is tag based (categories are a type of tag similar to the ways pages are just a form of post).
Read More ⟶

Improvements for Stattraq plugin.

April 29, 2007 by aaron
Ever since I originally started using Stattraq a few things bothered me about the way it worked. Here are the fixes to a few of them. Include pages with posts in your stats. Open stattraq.php Find: global $doing_rss, $p Replace With: global $doing_rss, $p, $page_id, $pagename, Find: if (($p != &#039;&#039;)){ $p = intval($p); $article_id = $p; } Replace with: if (($p != &#039;&#039;)){ $p = intval($p); $article_id = $p; }elseif (($page_id != &#039;&#039;)){ $page_id = intval($page_id); $article_id = $page_id; }elseif (($pagename != &#039;&#039;)){ $reqpage = get_page_by_path($pagename); if ( !empty($reqpage) ) $article_id = $reqpage->ID; } To add a list of all Pages that link to your site grouped by Website (excluding Google): Open “wp-stattraq/reporter/summary.php” Find: <?php echo PrintTimestamp();?> </div> <div id="queryTerms"> Before Add: <table id="referrersTable"> <thead> <tr> <th>#</th> <th>Referrer</th> <th>Pages</th> </tr> </thead> <tfoot> <tr> <th>#</th> <th>Referrer</th> <th>Pages</th> </tr> </tfoot> <tbody> <?php if($results){ $i=0; foreach($results as $row){ preg_match(&#039;/(http.*?\:\/\/.*?)(\/.*)/&#039;, htmlentities($row->ref), $matches); $ref_array[$matches[1]][] = $matches[2]; } while( list($site, $pages) = @each($ref_array) ){ if(strpos($site,&#039;google&#039;) ==false && $site != &#039;&#039;){?> <tr class="<?php echo ($i % 2 == 0 ?
Read More ⟶