11 2

How to force child categories to use the PARENT category template in Wordpress

After much digging around and trying to find a suitable plugin or PHP if/then statement, I came across a nice little site that did it for me using the functions.php page.

I would love to say I wrote this handy bit of code myself but I did not. Much praise to for the skilled coder at brassblogs.

Now, the way to use this is to take the code listed below and add it to your functions file. Or, to make it easier, I’ve pasted the complete information into this text file.

function inherit_template() {
if (is_category()) {
$catid = get_query_var('cat');
if ( file_exists(TEMPLATEPATH .
'/category-' . $catid . '.php') ) {
include( TEMPLATEPATH . '/category-' .
$catid . '.php');
exit;
}

$cat = &get_category($catid);
$parent = $cat->category_parent;
while ($parent) {
$cat = &get_category($parent);
if ( file_exists(TEMPLATEPATH
. '/category-' . $cat->cat_ID . '.php') ) {
include (TEMPLATEPATH
. '/category-' . $cat->cat_ID . '.php');
exit;
}
$parent = $cat->category_parent;
}
}
}

add_action('template_redirect',
'inherit_template', 1);

After you add that to your functions.php file, you simply need to make a template for EACH PARENT CATEGORY. The child categories will then use the template that their PARENT uses. YEA!

It’s very easy to make a category template. The simplest way is to take the existing archive.php file in your Wordpress theme and save it as category-ID.php where the ID is the NUMBER of the category. You can check this by going into your wp-admin, clicking on the category and reading the complete URL for the ID= (it will be at the end of the string).

So, if your category is #1, you will make category-1.php. You can style this page in any way you want; you can change link colors, text colors or even make it look completely different from the rest of your Wordpress blog – it’s completely up to you!

This will apply to all parent categories that you want to use a special template; simply find the category ID, create the page, name it category-XX.php (where XX is your category ID) and upload it to your theme folder. Or use the sample you can download here.

Again, credit goes to brassblogs.com! Thanks!



9 20

Display recent comments on your Wordpress blog

Sometimes you want to display a Wordpress feature, such as recent comments, tags, etc., without using a widget. For me, it’s occassionally easier to STYLE, especially if I’m not using a Theme that I built or that I’m familiar with.

A great code around is shown below, courtesy of to Kyle Eslick and found on wprecipes. I’ve used it on some sites and I find it works great. ONE NOTE: if you want less than 10 comments, simply change the code to a lesser number.

php
  global $wpdb;
  $sql = "SELECT DISTINCT ID, post_title, post_password,
comment_ID, comment_post_ID, comment_author,comment_date_gmt,comment_approved,
comment_type,comment_author_url,
SUBSTRING(comment_content,1,30) AS com_excerpt
FROM
$wpdb->comments LEFT OUTER JOIN $wpdb->posts ON
 ($wpdb->comments.comment_post_ID = $wpdb->posts.ID)
 WHERE comment_approved = '1' AND comment_type = ''
AND post_password = ''
ORDER BY comment_date_gmt DESC LIMIT 10";

  $comments = $wpdb->get_results($sql);
  $output = $pre_HTML;
  $output .= "\n


";
  $output .= $post_HTML;
  echo $output;



8 25

Facebook changes … again!

Effective August 23rd, well yesterday, there are some major changes to Facebook Fan Pages. Here’s a quick run down:

  1. The maximum width requirement for fan pages is now 520px.
  2. The boxes tag will be removed

How does this effect you, the Facebook user? If you have a page for your business, you will have to make changes to it. During the week of August 23rd, Facebook will automatically be implementing this change. That means that if you have a graphic page layout that is WIDER than the new width of 520 PX it will be truncated or rendered in such a way that it is basically useless.

Take this for example:

I think it's obvious that the owner of this fan page does NOT want it to look like this...

So, let everyone know – Facebook Fan Pages must now be 520PX wide and no wider – at least until Facebook decides to change again…