How can I redirect category to first available subcategory (child)?
Is that possible?
Thanks.
How can I redirect category to first available subcategory (child)?
Is that possible?
Thanks.
Ideas of code and a plugin:
http://wordpress.org/support/topic/257560?replies=6
(note: you'd need to use something like get_categories to get the 'first' child)
Thanks.
Now I have the following code:
$thiscategory = get_query_var('cat');
$catkids = get_categories("child_of=".$thiscategory."&sort_column=menu_order");
if ($catkids) {
$firstchild = $catkids[0];
wp_redirect(get_permalink($firstchild->ID));
}
The problem is $firstchild->ID I think, get_permalink should be replaced with something like get_category_link.
Problem solved, $firstchild->ID should be replace with $firstchild->term_id and of course get_category_link.
This worked for me... includes @akis' suggested corrections plus the proper parameters for get_categories (original snippet above uses parameters for "get_pages" per @MichaelH's original link).
<?php // redirect parent category to first child
$thiscategory = get_query_var('cat');
$cat_query = array (
'child_of' => $thiscategory,
'orderby' => 'id',
'order' => 'desc'
);
$catkids = get_categories($cat_query);
if ($catkids) {
$firstchild = $catkids[0];
wp_redirect(get_category_link($firstchild->term_id));
}
?>
For my purposes, I included this snippet in my custom category.php template.
ack... actually, scratch that ^^ --- causes an yet unresolved error: http://wordpress.org/support/topic/407556
This topic has been closed to new replies.