• Resolved luna2442

    (@luna2442)


    Hey all,

    So I have 2 (hopefully simple) questions;
    1. Can I make my posts in each category appear in reverse order? (oldest to newest)
    2. How do I get rid of the word “Category” on the category page? I would much rather it prefer just the category’s name.

    https://sagasonline.com/

Viewing 8 replies - 1 through 8 (of 8 total)
  • hyperbytes

    (@hyperbytes)

    Firstly, assuming you are using a child theme the following will allow you to specify if a category, tag or author is shown. It should be added to your child theme functions.php
    (code from stackexchange.com).
    add_filter( ‘get_the_archive_title’, function ($title) {
    if ( is_category() ) {
    $title = single_cat_title( ”, false );
    } elseif ( is_tag() ) {
    $title = single_tag_title( ”, false );
    } elseif ( is_author() ) {
    $title = ‘<span class=”vcard”>’ . get_the_author() . ‘</span>’ ;
    }
    return $title;
    });
    Secondly again add this code to your child theme functions.php code which allows you to specify how the posts are ordered etc. (reoplace “XXXX” with your post type

    function my_pre_get_posts( $query ) {

    // do not modify queries in the admin
    if( is_admin() ) {

    return $query;

    }

    // only modify queries for ‘xxxx’ post type. This code can be duplicated and repeated for multiple post types
    // simply change meta-key as required and order as required
    if( isset($query->query_vars[‘post_type’]) && $query->query_vars[‘post_type’] == ‘XXXX’ ) {

    $query->set(‘orderby’, ‘meta_value’);
    $query->set(‘meta_key’, ‘order’);
    $query->set(‘order’, ‘DESC’);

    }

    }

    hyperbytes

    (@hyperbytes)

    Sorry as you was oldest first last line should read:

    $query->set(‘order’, ‘ASC’);

    • This reply was modified 8 years ago by hyperbytes.
    Thread Starter luna2442

    (@luna2442)

    Thank you for the response! Unfortunately I am getting this.

    Parse error: syntax error, unexpected ‘class’ (T_CLASS)
    for
    $title = ‘<span class=”vcard”>’ . get_the_author() . ‘</span>’ ;

    maybe know why? Am a little stuck.

    • This reply was modified 8 years ago by luna2442.
    Thread Starter luna2442

    (@luna2442)

    Also, I am a little confused on how to apply these functions. I made it work without the author line of code for the time being, but how would I show the tag or category?

    Specifically, I want to show the author, the category Title only (eliminating just the word ‘category’).

    Thread Starter luna2442

    (@luna2442)

    Not to riddle you with replies, but the post order did not work. I want it for the category page specifically. I have a static front page so this doesn’t seem to be working when using the post type ‘post’

    Hi @luna2442!

    Give this bit of code a try for reversing the order of posts on category pages:

    
    // Reverse order of posts on category pages
    function reverse_category_order( $query ) {
        if ( $query->is_category() && $query->is_main_query() ) {
            $query->query_vars['order'] = 'ASC';
        }
    }
    
    add_action( 'pre_get_posts', 'reverse_category_order' );
    

    Place that in your child theme‘s functions.php file, and you should see your category pages reversed ??

    For the titles, if you want to remove the word Category, you can try this snippet (also in your child theme’s functions.php file)

    function my_archive_title( $title ) {
        $parts = explode( ':', $title );
        if ( count( $parts ) > 1 ) {
            $title = array_pop( $parts );
        }
        return $title;
    }
    add_filter( 'get_the_archive_title', 'my_archive_title' );

    Note – this will affect all archive pages on your site, not just categories. For example, it will also remove the word Tag: from tag archives, and remove Author: from author archives.

    Thread Starter luna2442

    (@luna2442)

    Thank you! This helped tremendously! Used the same bit of code to reverse the archive post order as well. Very much appreciated.

    You’re welcome!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Category Fine Tuning’ is closed to new replies.