Custom Category Templates on a Archive or Index page.

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.

  1. <?php $cat_temp = cat_loop();?>
  2. <?php if($cat_temp && is_numeric($cat_temp)){?>
  3. <?php include('loops/cat_'.$cat_temp.'.php');?>
  4. <?php }else{ ?>

Then add } just before the line endwhile.

The next step is to add the following to your theme’s functions.php file (you may have to create a file with the same name):

  1. function cat_loop(){
  2. global $blog_id,$post, $wp_version;
  3. if($wp_version >= 2.3){
  4. global $object_term_cache;
  5. $array = $object_term_cache[$blog_id][$post->ID]['category'];
  6. }else{
  7. global $category_cache;
  8. $array = $category_cache[$blog_id][$post->ID];
  9. }
  10. while (list($cat) = each($array)) {
  11. if(file_exists(dirname(__FILE__).'/loops/cat_'.$cat.'.php')){
  12. return $cat;
  13. }
  14. }
  15. }
  16. Use the following to copy and paste the code.

This can be modified to look at author’s also.

Continue reading. »

Oh, as an Aside: Displaying WordPress categories in a horizontal dropdown menu. (From the 16th of January)

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.

  1. <div style="text-align:center;">
  2. <ul id="menu" style="padding:0; margin:0;">
  3. <?php wp_list_categories('sort_column=name&sort_order=asc&style=list&children=true&hierarchical=true&title_li=0'); ?>
  4. </ul>
  5. </div>

I added this to my header.php, but you can add it anywhere you want it to appear.

The CSS is fairly simple and you just need to add it to your theme’s style.css file.

  1. ul#menu {
  2. margin: 0;
  3. padding: 0;
  4. list-style: none;
  5. width: 100%;
  6. font-size:1.2em;
  7. }
  8. ul#menu li {
  9. float: left;
  10. padding: 0;
  11. margin: 0;
  12. border-right:solid 1px #fff;
  13. }
  14. ul#menu ul li {
  15. float: none;
  16. position: relative;
  17. border-bottom: 1px solid #7EAED7; /* fixes gap problem in IE */
  18. border-left: 1px solid #FFF;
  19. z-index:1000;
  20. }
  21. ul#menu li ul {
  22. margin: 0;
  23. padding: 0;
  24. display:none;
  25. list-style: none;
  26. position: absolute;
  27. background: #9CC;
  28. }
  29. ul#menu ul ul{
  30. margin-left: .2em;
  31. position: absolute;
  32. top: 0; /* if using borders, -1px to align top borders */
  33. left: 100%;
  34. }
  35. ul#menu * a:hover, ul#menu li a:active{
  36. background:#7EAED7 !important;
  37. color: #FFFFFF;
  38. }
  39. ul#menu li a:link,
  40. ul#menu li a:visited,
  41. ul#menu li a:hover,
  42. ul#menu li a:active{
  43. display: block;
  44. padding: .2em .3em;
  45. text-decoration: none;
  46. background: #5587B3;
  47. color: #FFFFFF;
  48. }
  49. ul#menu ul li a:link,
  50. ul#menu ul li a:visited,
  51. ul#menu ul li a:hover,
  52. ul#menu ul li a:active {
  53. width: 8em;
  54. }
  55. Use the following to copy and paste the code.

Of course you will need to change the colors and text sizes to ensure it blends with the rest of the theme.

Continue reading. »

Designing flexible WordPress themes.

The average WordPress theme has different files for pages, single posts, archives and the front page; however, most of them are almost exactly the same except for inside the_loop. This is a quick tutorial on how to do the most with the fewest files, and includes a few methods to have custom templates by separating content display from structural elements.

WordPress looks first for special files and then defaults to the index.php file (as shown in this diagram). We can take advantage of this by using only an index.php file and then using conditionals to modify it. While it seems that this method would render the code less readable, it is actually far more readable, and far easier to modify.

Your theme should start off a header.php, footer.php, sidebar.php and an index.php. These files are the “code” files and are fairly self-explanatory, and at this point the only question should be whether you add just the header portion of the file to the header.php or everything including the calls to get_sidebar()—the same goes for the footer.php depending on your theme.

Continue reading. »

Thoughts on Those Who Walk In Darkness by John Ridley

In the course of this article the ending of the story and many other spoilers will be revealed. This is your only warning.

Continue reading. »

Creating a World- An Introduction and The Goals

I have always wanted to write a book. Not just any book; a good one. One that creates an entire universe and populates it; maybe not even a single book, maybe a whole series. Anyway, that’s not why this whole section is here. Instead this section will create a universe. As a basic foundation it will be similar to any Fantasy book or movie you have read. There will be Elves, Dwarfs, Goblins and Dragons. Instead of creating a world defined by the genre and within a tired cliche, I will try to breath new life into the old themes; in such a way that the universe I create is unique while still be familiar and accessible.

Continue reading. »