Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Brecht

    (@brechtvds)

    I’m afraid we don’t have that option right now.

    Technically you could use the “crp_output_list_item” plugin hook as mentioned here:
    https://www.ads-software.com/support/topic/show-featured-image-with-the-title/

    Thread Starter dev_John

    (@dev333)

    @brechtvds
    Thanks for the quick response!

    Thread Starter dev_John

    (@dev333)

    Hi @brechtvds

    I added this code to your plugin file (/helpers/output.php). And it works the way I wanted!
    Here are the changes (added lines “Customization”):

    
    $output .= '<div class="crp-list-item-title"><a href="' . $relation['permalink'] . '"' . $link_target . '>';
    $output .= $relation['title'];
    $output .= '</a></div>';
    
    /********** Customization **********/
    $relateddate = get_the_date( 'F j, Y', $relation['id'] );
    $relatedcat = get_the_category( $relation['id'] );
    $output .= '<div class="p-crp-list-item-date">' . $relateddate . '</div>';
    $output .= '<div class="p-crp-list-item-category">In "' . $relatedcat[0]->cat_name . '"</div>';
    /********** ********** **********/
    
    if ( in_array( CustomRelatedPosts::setting( 'template_image' ), array( 'below', 'right' ) ) ) {
          $output .= $image;
    }
    

    But I don’t know how to add this using a “crp_output_list_item” hook to avoid making changes directly to the plugin file (use a theme functions.php file instead), because every time I update the plugin I’ll have to add this code again.

    Thanks!

    • This reply was modified 5 years, 4 months ago by dev_John.
    Plugin Author Brecht

    (@brechtvds)

    You could try adding this to your (child) theme’s functions.php file:

    function crp_output_list_item( $output, $post_id, $relation ) {
    	$relateddevdate = get_the_date( 'F j, Y', $relation['id'] );
        $relateddevcategory = get_the_category( $relation['id'] );
        $extra_output = '<div class="dev-custom-crp-list-item-date">' . $relateddevdate . '</div>';
        $extra_output .= '<div class="dev-custom-crp-list-item-category">In "' . $relateddevcategory[0]->cat_name . '"</div>';
    
    	return str_replace( '</li>', $extra_output . '</li>', $output );
    }
    add_filter( 'crp_output_list_item', 'crp_output_list_item', 10, 3 );

    Take note that this will only work when using a list item container. You’d have to change the if you’re using something else.

    Thread Starter dev_John

    (@dev333)

    @brechtvds

    If I add this code to my theme functions.php file:

    
    function crp_output_list_item( $output, $post_id ) {
        // Some code
    }
    add_filter( 'crp_output_list_item', 'crp_output_list_item', 10, 2 );
    

    Will this code COMPLETELY replace the whole/entire function (function output_relation( $relation ) in /helpers/output.php) of your plugin?

    Thanks!

    Thread Starter dev_John

    (@dev333)

    @brechtvds

    I added the code you wrote to the theme’s functions.php file. And commented out my code in the plugin file (/helpers/output.php).
    This does not work, the category and date fields are no longer displayed on the page.

    Plugin Author Brecht

    (@brechtvds)

    Are you using an “Unordered List” as the container on the Settings > Custom Related Posts > Template page?

    Thread Starter dev_John

    (@dev333)

    @brechtvds

    Oh, sorry! Yes, It’s great!
    Thanks a lot for your help!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Display the date and category of the post’ is closed to new replies.