0

I have a page that lists all the posts from a given category of an custom post type dynamically. I do this with a plugin that list posts and a shortcod and with css i created 9 columns where they are sorted horizontal after letter. Instead I would like to have this in a vertical alphabetically dynamic ordered lists, preferably sorted under a letter. like this: http://skatematic.com/channels

Since css doesn't seem to cut it with this, I'm not sure where to start. Any pointers?

0
1

You can just simply create a custom query with WP_Query. You just need to make sure if you are using a custom taxonomy or the build-in category. For reference, see: Is There a Difference Between Taxonomies and Categories?

Here is an example for custom taxonomies (this can also be used for build-in categories, just change 'taxonomy' => 'MY_CUSTOM_TAXONOMY', to 'taxonomy' => 'category',):

$args = array(
    'post_type' => 'MY_CUSTOM_POST_TYPE',
    'posts_per_page' => -1,
    'orderby' => 'title',
    'order' => 'DESC',
    'tax_query' => array(
        array(
            'taxonomy' => 'MY_CUSTOM_TAXONOMY',
            'field'    => 'slug',
            'terms'    => 'THE_SLUG_FROM_MY_TERM',
        ),
    ),
);

$the_query = new WP_Query( $args );

// The Loop
    echo '<ul>';
    while ( $the_query->have_posts() ) {
        $the_query->the_post();
        echo '<li>' . get_the_title() . '</li>';
    }
    echo '</ul>';

/* Restore original Post Data */
wp_reset_postdata();

For a single term, you can also work directly with the query vars, so you can change your $args to something like this

$args = array(
    'post_type' => 'MY_CUSTOM_POST_TYPE',
    'posts_per_page' => -1,
    'orderby' => 'title',
    'order' => 'DESC',
    'MY_CUSTOM_TAXONOMY'    => 'THE_SLUG_FROM_MY_TERM',
);

If you have a built-in category, change your $args to the following

$args = array(
    'post_type' => 'MY_CUSTOM_POST_TYPE',
    'posts_per_page' => -1,
    'orderby' => 'title',
    'order' => 'DESC',
    'cat'    => 'THE_ID_OF_YOUR_CATEGORY',
);

For more useful parameters and the use there of, go and check out WP_Query in the codex

7
  • Im probably the stupidest guy in the world, but my whole question came ut totaly wrong. I meant to say I have the list in 9 columns and i wanted it sorted alphabetically and vertical, not horizontal which is the case now. Aug 22 '14 at 7:57
  • Sorry, but this is a styling issue then, making your question off topic. This should be better asked then on stackoverflow.com Aug 22 '14 at 8:05
  • Um ive been told css and vertically alphabetically columns is impossible. I did find this, so maybe paired with your wp_query could be something: code.nxil.com/2013/07/23/column-list-alphabetical-order-query Aug 22 '14 at 8:12
  • Can't say on the top of my head now, but my query should be more than enough, don't see the need for so many queries. My php is not up to scratch, by I would think that if you add the query results to an array, and then sort that array accordingly, you should be able to achieve what you want Aug 22 '14 at 8:23
  • Have a look at this question and this answer Aug 22 '14 at 8:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.