Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter MagicB85

    (@magicb85)

    I solved it.

    In functions.php I added this lines in date section:

    $id = get_the_ID();
    $categories = get_the_category();
    if ( ! empty( $categories ) ) {
    	$date .=  sprintf(__(' in %s', 'recent-posts-widget-extended' ), $categories[0]->name );
    }

    where exactly did you place the code within functions.php?
    it’s not working on my end

    and would this change affect only new recent posts or all?

    Thread Starter MagicB85

    (@magicb85)

    This is how my code looks now:

    if( $args['date'] ):
    	if ( $args['date'] ) :
    		$date = get_the_date();
    		if ( $args['date_relative'] ) :
    			$date = sprintf( __( '%s ago', 'recent-posts-widget-extended' ), human_time_diff( get_the_date( 'U' ), current_time( 'timestamp' ) ) );
    		endif;
    	elseif ( $args['date_modified'] ) : // if both date functions are provided, we use date to be backwards compatible
    		$date = get_the_modified_date();
    		if ( $args['date_relative'] ) :
    			$date = sprintf( __( '%s ago', 'recent-posts-widget-extended' ), human_time_diff( get_the_modified_date( 'U' ), current_time( 'timestamp' ) ) );
    		endif;
    	endif;
    	$id = get_the_ID();
    	$categories = get_the_category();
    	if ( ! empty( $categories ) ) {
    		$date .=  sprintf(__(' in %s', 'recent-posts-widget-extended' ), $categories[0]->name );
    	}
    	$html .= '<time class="rpwe-time published" datetime="' . esc_html( get_the_date( 'c' ) ) . '">' . esc_html( $date ) . '</time>';
    endif;

    Thank you MagicB85!

    I’ve been working on this for weeks. You are the only one to provide a solution that works! TYTYTYTYTY!!!!

    To sweets6 or anyone having problems finding where to put the code:

    After searching ad nauseum this evening, I finally found where that code goes. It goes in the *WIDGET’s* functions.php file.

    In retrospect it seems obvious that a widget would have its own functions.php. That little tidbit of info is going to help me tremendously in customizing a few other widgets that have been driving me crazy. <JOY>

    Apparently, WP-Dashboard/Appearance/Editor does not show widget files. Well out of equal parts desperation and curiosity, I checked out yesterday’s site-backup (complete ftp copy of entire wp folder) and tracked it down (functions.php) that way.

    Find the widget’s functions.php file like this:
    /yourroot/wp-content/plugins/recent-posts-widget-extended/includes/functions.php

    You have to open each of those folders one by one til you get to the widget’s functions.php, then edit it in notepad/dreamweaver then upload.

    DISCLAIMER: ALWAYS MAKE A BACKUP (ie create functions_bak.php) before you change code.

    FYI, At first it didn’t work, just adding the few lines of code. Got the dreaded “internal server error.” So I copied the entire codeblock from the answer above. WORKED LIKE A CHARM!!!

    Thanks again, MagicB85!

    sorry my issue is that i’m only putting the code in my css for this plugin and it’s not for a widget on my sidebar
    It’s actually for my homepage
    Under each image, I want my title, date, description and hopefully, a category display…
    any input?

    Sweets6, Since no one else has answered you I will guess that no matter where you want to display the list, you must add that code as directed above. Did you try it to see? (It works for me in both sidebar and regular list on a content page because of doing the fix above.)

    To show category title, use below code in functions.php

    $html .= get_cat_name( $args[‘cat’] ) ;

    This will work as you want.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Show category after date’ is closed to new replies.