Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Bill Erickson

    (@billerickson)

    You will need to use the output filter to change the order of the post elements.

    See the examples here: https://www.billerickson.net/code/using-display-posts-shortcode-output-filter/

    Thread Starter keithfoggan

    (@keithfoggan)

    I’ve followed the instructions and added the code below before the /?> in the functions.php file.

    /**
    * DPS – Move category before title
    * @see https://www.billerickson.net/code/using-display-posts-shortcode-output-filter
    *
    */
    function be_dps_move_category_before_title( $output, $original_atts, $image, $category_display_text, $title, $date, $excerpt, $inner_wrapper, $content, $class ) {
    $output = ‘<‘ . $inner_wrapper . ‘ class=”‘ . implode( ‘ ‘, $class ) . ‘”>’ . $image . $category_display_text . $title . $excerpt . $content . $date . ‘</’ . $inner_wrapper . ‘>’;
    return $output;
    }

    Not seeing any change in the site though, category still follows after the other elements (title, date, author).

    Am I doing something wrong?

    Plugin Author Bill Erickson

    (@billerickson)

    You need to include the last line:

    add_filter( 'display_posts_shortcode_output', 'be_dps_move_image_after_title', 10, 9 );

    You defined the function, but the last line applies that function to the shortcode’s output.

    Thread Starter keithfoggan

    (@keithfoggan)

    When I try that the posts disappear – doing something wrong?

    /**
    * DPS – Move category before title
    * @see https://www.billerickson.net/code/using-display-posts-shortcode-output-filter
    *
    */
    function be_dps_move_category_before_title( $output, $original_atts, $image, $category_display_text, $title, $date, $excerpt, $inner_wrapper, $content, $class ) {
    $output = ‘<‘ . $inner_wrapper . ‘ class=”‘ . implode( ‘ ‘, $class ) . ‘”>’ . $image . $category_display_text . $title . $excerpt . $content . $date . ‘</’ . $inner_wrapper . ‘>’;
    return $output;
    }

    add_filter( ‘display_posts_shortcode_output’, ‘be_dps_move_image_after_title’, 10, 9 );

    Plugin Author Bill Erickson

    (@billerickson)

    It looks like your function names don’t match. At the top you’re using be_dps_move_category_before_title() as the name, but in the add_filter line you’re using be_dps_move_image_after_title().

    Change the code to this:

    
    /**
    * DPS – Move category before title
    * @see https://www.billerickson.net/code/using-display-posts-shortcode-output-filter
    *
    */
    function be_dps_move_category_before_title( $output, $original_atts, $image, $category_display_text, $title, $date, $excerpt, $inner_wrapper, $content, $class ) {
    $output = ‘<‘ . $inner_wrapper . ‘ class=”‘ . implode( ‘ ‘, $class ) . ‘”>’ . $image . $category_display_text . $title . $excerpt . $content . $date . ‘</’ . $inner_wrapper . ‘>’;
    return $output;
    }
    
    add_filter( ‘display_posts_shortcode_output’, ‘be_dps_move_category_before_title’, 10, 9 );
    
    Thread Starter keithfoggan

    (@keithfoggan)

    Tried that – seemed to cause a page issue, the site wouldn’t load with that code added, any ideas?

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Category before Title’ is closed to new replies.