Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.