Blog

You are browsing the archive for WordPress.

Use the same Category Template for all Child Categories

January 4, 2010

This is a relatively undeveloped code so it hasn’t been tested and I would not suggest using this for production.

How to use the same category-slug.php template for the category and all child categories?

<?php
/**
FORCE CHILD CATEGORIES TO USE PARENT CATEGORY TEMPLATE
Modified code from http://codex.wordpress.org/User:Lorelle/Custom_Category_Template
v0.2
*/
	$jasbt_get_cat = get_category($cat);
	// LET'S FIND OUT IF THIS IS A PARENT CATEGORY PAGE
	if ($jasbt_get_cat->category_parent == 0) {
		$jasbt_get_cat->category_parent = $cat;

	} else {

		// IF PARENT CATEGORY IS "FOO" THEN USE "/CATEGORY-FOO.PHP" THEMPLATE
		$parent_category = get_category($jasbt_get_cat->category_parent);

		// Edit parent category name from 'FOO' to either 'ID', 'category-slug', or 'Category Name'
		if ($parent_category->cat_name == 'FOO') { 

			// Edit the category template from 'category-foo.php' to '/category-ID.php' or '/category-slug.php'
			include(TEMPLATEPATH. '/category-FOO.php');
			exit; // All done.
		}
	}
// IF NOT FORWARDED, CONTINUE WITH THEME ?>
<?php get_header(); ?>

Explanation: If the cat is a parent category, then it does nothing and continues reading either the category.php file or the archive.php (if it cannot find the category.php file then it will look for the archive.php file; then if that one isn’t there, it will use the index.php file). If it has both, then it will first look at the category.php and in which case you’ll want the code there. If the category.php file is not present, then use this code in the archive.php file.

Development: This code is under development and, to me, looks sloppy but it’s a start.

Unique Templates for Categories

January 4, 2010

Recently, I have been developing a theme with special features and figured that I can post some WordPress code goodies here.

How to assign a different category template for a category or a sub-category.

Place the following code before the get_header() hook on the archive/category theme file (i.e. archive.php or category.php file).

In this example, I do not have ‘/category.php’ template because I’m using the ‘/archive.php’ template (click here for WordPress Template Hierarchy diagram ). Instead, I want to assign category templates to certain categories and then continue using my archive template as is.

I want the “Foo” category to have it’s own style separate from other categories and so I created a ‘/category-foo.php’ template file with its own style and added the following code to the first line of my ‘/archives.php’ template file.

<?php
	if (in_category('ID' or 'foo-slug' or 'Foo Name')) {
		include(TEMPLATEPATH . '/category-foo.php');
		exit;
	}
?>

If you have multiple categories that will be assigned to other theme files, then use this code:

<?php
	if (in_category('ID' or 'cat-slug' or 'Cat Name')) {
		include(TEMPLATEPATH . '/cat-template.php');
		exit;
	}
	elseif (in_category('ID' or 'other-cat-slug' or 'Other Cat Nam')) {
		include(TEMPLATEPATH . '/other-cat-temp.php');
		exit;
	}
?>

Unfortunately, this code only works for the parent category or child category that it is specifically assigned and does not automatically work for the child categories of the assigned. I’m currently working on a hack for that.

WP Footer HTML

December 16, 2009

Formerly WPMU Footer HTML at InstalledDesign.com now on RGVRockCity.com Web site developement.

Ever get tired of having to update the footer to every theme you upload to your WordPress powered Web site?

This plugin enables admins to add a piece of arbitrary HTML to the footer of their WP Theme. Compatible with WPMU. The WP theme or WPMU theme must have the wp_head() and wp_footer() hooks to function properly. Currently there is no backend support and the file must be edited using a TEXT or PHP editor.

http://rgvrockcity.com/wp-content/plugins/downloads-manager/img/icons/winzip.gif

download: WP Footer HTML (871B)

added: 16/12/2009
clicks: 32

description:

Formerly WPMU Footer HTML at InstalledDesign.com. This plugin enables admins to add a piece of arbitrary HTML to the footer of their WP Theme. Compatible with WPMU. The WP theme or WPMU theme must have the wp_head() and wp_footer() hooks to function properly. Currently there is no backend support and the file must be edited using a TEXT or PHP editor.
btn_donateCC_LG

donations:

Donations are appreciated and always accepted. If you have found this download useful, please consider donating a couple of bucks for the cause.

Installation:

WordPress Single Install – Un-zip the file and upload to your http://example.com/wp-contents/plugins/ directory.  The arbitrary HTML will appear in the footer of the theme even after you change themes.

WordPress MU Install – Un-zip the file.  Edit the file using a text or PHP editor and upload to your http://example.com/wp-contents/mu-plugins/ directory.  The arbitrary HTML will appear site-wide.

Editing:

The plugin works on two WordPress hooks, wp_head() and wp_footer(), so any theme must have those two hooks to function properly.

CSS – Edit the code within the specified text.

<!-- START WP FOOTER HTML CSS -->
<style type="text/css">
div#wp-footer-html    {
 text-align: center;
}
</style>
<!-- END WP FOOTER HTML CSS -->

HTML – Edit the code within the <div> tags.

<div id="wp-footer-html">
 <p>Powered by <a href="http://wordpress.org">WordPress</a>.
 <?php
 $theme_data = get_theme_data(TEMPLATEPATH . '/style.css');
 echo $theme_data['Title'] . '&nbsp;';
 echo $theme_data['Version'] . '&nbsp;by&nbsp;';
 echo $theme_data['Author'];
 ?>.</p>
</div><!-- id="wp-footer-html" -->

WP-ADMIN – Uncomment the lines to have footer appear in the Dashboard area.

<?php } // DO NOT EDIT PAST THIS LINE!!!
add_action('wp_head','jaswpfooter_css');
add_action('wp_footer','jaswpfooter_html');
// UN-COMMENT THE FOLLOWING LINES IF YOU WANT THE FOOTER TO APPEAR IN THE WP-ADMIN AREA
// add_action('admin_head','jaswpfooter_css');
// add_action('admin_footer','jaswpfooter_html','1');
?>

Development:

Anyone is welcome to work on this plugin, however, I ask that you let us know what edits have been made to include it in future releases.

:) Enjoy!