You could get your answer from Kovshenin blog
Replace whole if ( $comments )
with this
if ( $comments ) {
foreach ( (array) $comments as $comment) {
$comm_post_id = $comment->comment_post_ID;
if ( $category_name ) {
if (!in_category( "{$category_name}", $comm_post_id )) {
continue;
}
}
$output .= '<li class="recentcomments">' . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link(), '<a href="' . esc_url( get_comment_link($comment->comment_ID) ) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>';
}
}
Related Posts:
- Programmatically add widgets to sidebars
- Loading scripts only if a particular shortcode or widget is present
- Give Editor Access To Sidebar
- Where is the content of widgets stored in mysql table
- Get number of widgets in sidebar
- Add the sidebar/widget editor to the post edit screen?
- Show Woocommerce minicart widget in checkout page sidebar? And, how to make this update secure by overriding widget?
- Different widgets on different page templates?
- Widgets not displaying in theme customizer
- Register multiple sidebars
- How to add author details in the post sidebar?
- Determining a Widget Instance and Sidebar Location?
- Randomize widgets displayed in my sidebar [duplicate]
- Add div class to only one widget
- Add a select box to all widgets
- How to avoid widgets added to sidebar on theme activation?
- Call sidebar from a template
- Adding classes to dynamic sidebar
- Display sidebar that created in functions.php
- Create variable from widget instance
- Save/update widget outside admin panel [closed]
- WordPress: Apply filter/hook to a particular sidebar widgets?
- Why use dynamic_sidebar() conditionally?
- wordpress widget textbox in the sidebar
- WordPress Widget multiple use
- Contact Form in sidebar [closed]
- More flexible sidebar and widget management
- WordPress widget new instance creates content duplicates
- dynamic_sidebar() returns false in admin section
- Moving comments section to left of content (Twenty Thirteen)
- duplicate sidebar
- How to check if searchform.php is being included as widget?
- How to get sidebar’s content inside admin-ajax?
- Removing custom widget area WordPress 4.4 [closed]
- Full width layout for custom post type pages
- How to “pair” two widgets side by side in one sidebar [closed]
- Adding custom html and standard widgets to sidebar
- Dynamic Sidebars On Multiple Subpages
- How to add new sidebar widget area to child theme?
- Cannot save widgets in custom sidebars
- Check which registered sidebar a widget is added to
- Disable widgets on specific posts
- Display the id list of active widgets of same sidebar?
- How to remove a widget from the sidebar on specific page?
- Add individual tag to widget title in sidebar
- Excluding specific widgets from default sidebar class
- Can WordPress Read Its Own RSS Feed?
- Can’t see widget areas in my customizer
- Dynamic sidebar based on category
- Widgets not activated alert after using get_sidebar()
- How to show different widgets on different pages in a user friendly way
- Show widget differently depending on if it’s in the sidebar or footer
- Trying to create dynamic widget area using post ID
- Can you target a widget_class in a register_sidebar?
- Display attachment, post and page in recent comments widget
- Default widgets assignment – isn’t working
- Copy Widget Settings because of changed IDs
- Programmatically add widgets to sidebars
- Programmatically add widgets to sidebars
- How to call widget by widget’s id?
- wp_get_attachment_image() not displaying post images even though wp_get_attachment_url() echo correct urls
- Show a widget as a sidebar fallback
- register_sidebar fails when using a include within functions.php
- Add a specific css to a widget
- Different sidebars not changing
- Is there a simple way to have a new sidebar for each page?
- how to add the same Widget twice to a sidebar?
- Filter Text from sidebar widget?
- Add class to on sidebar widget
- My widget not printing before_widgets and after widgets
- Multiple rows of footer widget areas
- Output column number according to active sidebars
- Check if widget is inside sidebar with PHP
- New Widget are not showing
- How do I exclude portrait pictures from the nextgen gallery sidebar widget?
- Upgraded to 3.3, My Widgets Disappeared
- changing the style of sidebar
- recent comments filter by author, page, category
- WordPress Local to Live and The Missing Widgets!
- Need to delete the sidebar widget area and have the page a full page rather than just have a blank widget area
- Before_widget won’t show up
- Reposition the widget sidebar in Appearance->Widgets
- Handling dozens of sidebars
- Does current page contain widget or sidebar
- widgets_init actions not fired from functions.php’s child theme
- Active Sidebar Conditional Question?
- Target logic based on Widget / Sidebar Name
- Paginate recent posts widget
- Add sidebar in inner pages
- $before/after_widget/title not displaying anything
- Inkness theme sidebar
- Automatically hide Widgets that would lengthen page
- Single Widget Multi Sidebar
- Unique widget id in sidebar
- How to exclude a widget from showing up on a page?
- How to hide sidebar widgets in all pages except Hompage?
- Subpages menu on sidebar plus widgets
- Keeping shortcode-generated widget and theme element in one line [closed]
- Add custom settings to widget areas
- Can’t edit the widgets sidebar or footer