Jump to content

How to pass a variable to a function as an argument?


jcpeden

Recommended Posts

I'm working on a custom category page for a Wordpress theme and I need to pass (correct me if that is the wrong terminology) to an argument for the function get_categories:

 

if (is_category('4,6,9')) {

?>

 

<?php $categories = get_categories("child_of=$cat-id");

 

foreach ($categories as $cat) {

query_posts("cat=$cat->cat_ID&showposts=-1&order=ASC&orderby=name");

 

I would like $cat-id to be either 4, 6 or 9 depending on which category page the user is looking at. How do I make this happen?

Here is what I've come up with. I've tested this code and the results are absolutely perfect for what I need. As I'm pretty much a beginner with PHP, please let me know if I've gone about it in an a$$ backward manner.

 

// Get current category id and concatenate argument 'child_of=cat_id'

function child_categories(&$current_cat_ID) {

global $wp_query;

$current_cat_ID .= get_query_var('cat');

}

$child_of = 'child_of=';

child_categories($child_of);

 

// Get child categories of current category

$categories=get_categories($child_of);

 

Apologies if I've explained myself badly

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.