WordPress.org

Forums

Order post alphabetically by category (10 posts)

  1. jumust
    Member
    Posted 3 years ago #

    Hi,
    I have in category page created for a custom post type A : A_category.php

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    MY CONTENT
    	<?php endwhile; endif; ?>

    It gets all posts correctly in each current subcategory, in chronologically order but I want them to be alphabetically sorted

    I tried this

    <?php
    $args = array( 'post_type' => 'A', 'posts_per_page'=>10, 'orderby'=>'title','order'=>'ASC');
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
    ?>
    MY CONTENT
    	<?php endwhile; endif; ?>

    but in each subcategory it gets all custom posts from all subcategories and not from the current category. how can I do?

  2. NITRO1250
    Member
    Posted 3 years ago #

    Here, use this plugin: http://wordpress.org/extend/plugins/list-category-posts/

    It would save you so much time rather than manually coding and it does exactly what you want and more.

    In your case, you can get the specific id for the category and list them all to be sorted in any way you want.

    I'm using this plugin on 2 WP sites to handle all the bulk sorting.

  3. jumust
    Member
    Posted 3 years ago #

    Sounds like it may be a good fit!
    So considering the code I wrote above how can I insert the shortcode in the template after I install the plugin?

    In my case I think I should use shortcode like [catlist categorypage=yes orderby=title order=ASC post_type=A]

  4. NITRO1250
    Member
    Posted 3 years ago #

    That should do it.

    Add this to the end of the shortcode: numberposts=-1

    It will display ALL posts in the category, not just a limited number. Took me a while to figure that out months ago.

    You can add shortcode to any page or post or widget block (custom plugin) and it will spit out everything you need in any of the options that you see there. It works perfectly and I couldn't live without it!

  5. jumust
    Member
    Posted 3 years ago #

    Good!

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    MY CONTENT
    	<?php endwhile; endif; ?>

    Ok so in the template I use do_shortcode function?
    And how about endwhile?

  6. NITRO1250
    Member
    Posted 3 years ago #

    Actually, you wouldn't use any code (php). Just create a post or page that you want to have showing a list of posts and add the shortcode to the post/page content and it displays it for you.

    Here is an example: http://diebunker.com/teaching/fall-2010-dms231-3d-modeling/
    I created a page and then inserted a catlist shortcode to pull all the posts from that category into a nice simple list.

    Is this what you are looking for in some way? Keep in mind, you can add whatever you want as far as text above or below the catlist shortcode. I didn't need it in this specific case.

    I'm currently working on a several hundred post site right now where I use catlist extensively to save editing many pages.

  7. jumust
    Member
    Posted 3 years ago #

    Yes but actually I need to use it in the file template .php, because I need to use a loop

  8. NITRO1250
    Member
    Posted 3 years ago #

    Hmm... that would be tricky. I'm out of ideas as far as integrating it into that specifically, however what you could do is take a look at the catlist plugin code and see if you can find anything helpful that you can use. That is what I honestly would do in your situation.

  9. jumust
    Member
    Posted 3 years ago #

    Thanks! It sounds difficult for me to do that....

    Any other ideas on this thread "Order post alphabetically by category"?

  10. vtxyzzy
    Member
    Posted 3 years ago #

    That plugin allows you to create your own template that is called from the shortcode. Take a look at the default.php example code in the list-category-posts/templates/ directory.

Topic Closed

This topic has been closed to new replies.

About this Topic