Revisions
- November 5, 2012 @ 23:31:25 [Current Revision] by PeterLugg
- November 5, 2012 @ 23:26:27 by PeterLugg
Revision Differences
November 5, 2012 @ 23:26:27 | Current Revision | ||
---|---|---|---|
Content | |||
Unchanged: Get only the top level categories. There is no depth parameter on the get_categories function, this query and foreach loop will ensure only toplevel categories are displayed: | Unchanged: Get only the top level categories. There is no depth parameter on the get_categories function, this query and foreach loop will ensure only toplevel categories are displayed: | ||
Added: [php] | |||
Added: <?php | |||
Added: $args=array( | |||
Added: 'taxonomy' => 'product_cat', | |||
Added: 'hierarchical' => '1', | |||
Added: 'hide_empty' => '0', | |||
Added: 'pad_counts' => '1', | |||
Added: 'orderby' => 'term_order' | |||
Deleted: | Added: ); | ||
Added: $categories=get_ categories($args); | |||
Added: foreach($categories as $category) { | |||
Added: if($category->parent == 0 ){ | |||
Added: echo '<p><a href="'. get_term_link( $category->slug, 'product_cat') .'" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category-> name.'</a> '. $category->count . '</p> '; | |||
Added: } | |||
Added: } | |||
Added: ?> | |||
Added: [/php] | |||
Unchanged: This query will get just the child categories of a given parent: | Unchanged: This query will get just the child categories of a given parent: | ||
Deleted: | |||
Added: [php] | |||
Added: <?php | |||
Added: $categoryID = $category->term_id; | |||
Added: $args=array( | |||
Added: 'taxonomy' => 'product_cat', | |||
Added: 'child_of' => $categoryID, | |||
Added: 'hide_empty' => '0', | |||
Added: 'orderby' => 'term_order' | |||
Added: ); | |||
Added: $categories=get_ categories($args); | |||
Deleted: In conjunction with the 'Custom Taxonomy Order' plugin and The two queries above can be combined to return a custom ordered list of categories with multiple levels. | Added: foreach($categories as $category) { | ||
Added: echo '<p>- <a href="'. get_term_link( $category->slug, 'product_cat') .'" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category-> name.'</a> '. $category->count . '</p> '; | |||
Added: } | |||
Added: ?> | |||
Added: [/php] | |||
Added: In conjunction with the '<a href="http:// wordpress.org/ extend/plugins/ order-up-custom- taxonomy-order/" target="_blank">Custom Taxonomy Order</a>' plugin and an orderby parameter of 'term_order', the two queries above can be combined to return a custom ordered list of categories with multiple levels. | |||
Added: [php] | |||
Added: <?php | |||
Added: $args=array( | |||
Added: 'taxonomy' => 'product_cat', | |||
Added: 'hierarchical' => '1', | |||
Added: 'hide_empty' => '0', | |||
Added: 'pad_counts' => '1', | |||
Added: 'orderby' => 'term_order' | |||
Added: ); | |||
Added: $categories=get_ categories($args); | |||
Added: foreach($categories as $category) { | |||
Added: if($category->parent == 0 ){ | |||
Added: echo '<p><a href="'. get_term_link( $category->slug, 'product_cat') .'" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category-> name.'</a> '. $category->count . '</p> '; | |||
Added: $categoryID = $category->term_id; | |||
Added: $args=array( | |||
Added: 'taxonomy' => 'product_cat', | |||
Added: 'child_of' => $categoryID, | |||
Added: 'hide_empty' => '0', | |||
Added: 'orderby' => 'term_order' | |||
Added: ); | |||
Added: $categories=get_ categories($args); | |||
Added: foreach($categories as $category) { | |||
Added: echo '<p>- <a href="'. get_term_link( $category->slug, 'product_cat') .'" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category-> name.'</a> '. $category->count . '</p> '; | |||
Added: } | |||
Added: } | |||
Added: } | |||
Added: ?> | |||
Added: [/php] |
Note: Spaces may be added to comparison text to allow better line wrapping.
No comments yet.