6 Must Have Plugins for Your WordPress Installs
In my experience with custom WordPress installs, I found myself installing the same plugins over and over. What I’ve done to increase my efficiency of installing WordPress, I took all my most used plugins and dropped them into the plugin folder of my WordPress install package. (more…)
Posted on January 4, 2010 in WordPress Plugins and has been tagged as plugins, wordpress.
How to Exclude a Category from the WordPress Loop
Here’s the question that was asked:
“Basically I want to take all of the posts in the “Freelance” category and remove them from the main content so that I can link to them from a page instead of including them in the Loop. ”
Here is the code to exclude an entire category from appearing within the WordPress loop:
<?php query_posts('cat=-3'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<?php the_content(); ?>
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
Basically, what you’re doing with the above code is telling the loop that if it’s in category 3, just remove it from the query that the loop is using.
Hopefully you’ve found this quick tutorial valuable. Contact me if you have any questions or would do it a different way. There’s 1,001 ways to do everything – that’s why I love coding.
Posted on July 23, 2009 in Wordpress How-To's and has been tagged as wordpress.
Great Grand Parent ID’s in WordPress
Have you ever needed to find all the ancestor ID’s of a page in WordPress? If so, you’ve come to the right place. Here’s some quick code to give you up to the great grand parent ID.
$current = $post->ID;
$parent = $post->post_parent;
$get_grandparent = get_post($parent);
$grandparent = $get_grandparent->post_parent;
$get_greatgrandparent = get_post($grandparent);
$greatgrandparent = $get_greatgrandparent->post_parent;
echo "parent = $parent; grandparent = $grandparent; greatgrandparent = $greatgrandparent";
If you wanted to, you could continue this pattern to N number of ancestors…
Hopefully you’ve found this quick tutorial valuable. Contact me if you have any questions or would do it a different way. There’s 1,001 ways to do everything – that’s why I love coding.
Posted on July 10, 2009 in Wordpress How-To's and has been tagged as wordpress.
Style WordPress Titles Based on Number of Letters
A common problem that I’ve encountered – how to control dynamic text based on how long it is. In this case I had titles ranging from 10 characters to 25 characters – this includes spaces. The goal is to make them centered regardless of how many letters and spaces are in the title.
Here is an example of one of the shorter titles I was given:

Here is an example of one of the longer titles I was given:
A series of quick if/else statements and use of the strlen function in PHP allows me to assign different classes depending on the length of the dynamic title. I figured out, based on the CSS on the H1 class, that 14 was my magic number.
Here’s the quick snippet of code I used:
$title = $post->post_title;
$char_title = strlen($title);
if ($char_title > 14) {$header_style = "double";}
else {$header_style = "single";}
I grab the post title using common WordPress calls and make it into the $title variable. The I use the strlen function to determine the number of characters (including spaces) in the title. If it’s greater than 14, it assigns the $header_style variable the class “double” or else it assigns it the “single” class.
Here is how I used it within the WordPress loop:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="<?php echo $header_style ?>"><h2><?php the_title(); ?></h2></div>
<?php endwhile; endif; ?>
Hopefully you’ve found this quick tutorial valuable. Contact me if you have any questions or would do it a different way. There’s 1,001 ways to do everything – that’s why I love coding.
Posted on July 8, 2009 in Wordpress How-To's and has been tagged as css, php, wordpress.