Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Trying to display a category by an odd sequence and have the following:

<?php wp_list_categories('orderby=id&include=4,5,6,7,8,9,10,72,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41'); ?>

notice after ID #10 it jumps to ID #72. How can I code this better?

Note: Names are not alphabetical and numbers are not sequential, so just need to display IDs #4 to #10, #72, #11 to #41 listed in that order.

Respectfully, jw

share|improve this question

3 Answers 3

You could do something like this:

<ul>
<?php
wp_list_categories('order_by=ID&title_li=&include=4,5,6,7,8,9,10');
wp_list_categories('order_by=ID&title_li=$include=72');
wp_list_categories('order_by=ID&title_li=&include=11,12,13,14,15,16,17, 18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41');
?>
</ul>

Just listing them in order for the include arg won't help you since that only goes into the WHERE clause, not into the ORDER BY clause of the SQL query.

share|improve this answer
    
Well, I feel stupid. I thought I had tried that a few hours ago, thank you wyrfel, it certainly worked. :) –  user3376 Feb 22 '11 at 3:52

I've not used it, but you may be interested in the My Category plugin.

share|improve this answer
    
Thank you, I will look into it but I am more interested in a programmatic solution this time. :) –  user3376 Feb 22 '11 at 0:35
    
I just tried the plugin and it didn't work...I also tried the Category Order plugin and that was not what I needed either. –  user3376 Feb 22 '11 at 3:40

Easy, if i understood a little bit (of your question) right...

$args_include = array(4,5,6,7,8,9,10,72,11,12,13,14,15,16,17, 18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41)';
$args_include = sort( $args_include, SORT_NUMERIC);

wp_list_categories( 'orderby=id&include='.$args_include );

...but i guess i haven't. So, what have the includes in common? And what "Note: Names are not alphabetical and numbers are not sequential" does that mean? I can't see any names, only IDs.

share|improve this answer
    
Thanks for your time kaiser, –  user3376 Feb 22 '11 at 1:28
    
Thank you for your time kaiser. What I meant is I can't seem to order by title since the title names would not provide the correct sequence. I tried wp_list_categories('orderby=id&title_li=&include=4...72...41'); which placed 72 last. So, I was hoping there was a way to order by a range, like [4-10,72,11-41] or something similar. –  user3376 Feb 22 '11 at 1:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.