How to create a category post widget?
-
Hello. I’m an old friend of wordpress but new to ‘coding’
I found this from a year ago – Show posts from a specific category
Hi Alex,
Is it possible to show posts from a specific category on the sidebar?
Acosmin
If you are not using the recent posts widget open ..acosmin/widgets/custom-recent-posts-widget.php and bellow
‘posts_per_page’ => $recent_posts_number,
add this line:‘cat’ => 4,
where 4 represent your category id.
After that eneble the recent posts widget
Now I looked in the theme editor but am unable to find anything called “acosmin/widgets/custom-recent-posts-widget.php ”
or
“‘posts_per_page’ => $recent_posts_number”
which i can alter (by putting in ‘cat’ => 4….
Can anyone help me please?
I want to have a specific category of posts in the sidebar but only want to use Acosmin’s great widgets.
Thanks
-
Ok I figured out I had to edit the php file in C-Panel..
..and put ‘cat’ =>3 below the line mentioned above. 3 being the number of the category name as far as I can tell.
class AC_Recent_Posts_Widget extends WP_Widget {
function AC_Recent_Posts_Widget() {
// Settings
$widget_ops = array( ‘classname’ => ‘ac_recent_posts_widget’, ‘description’ => ‘Displays your most recent articles. With or without thumbnails’ );// Create the widget
$this->WP_Widget( ‘ac_recent_posts_widget’, __(‘ACOSMIN: Recent Posts’, ‘acosmin’), $widget_ops );
}function widget( $args, $instance ) {
extract( $args );// Widget Settings
$title = apply_filters(‘widget_title’, $instance[‘title’] );
$recent_posts_number = $instance[‘recent_posts_number’];
$hide_recent_thumbs = isset( $instance[‘hide_recent_thumbs’] ) ? $instance[‘hide_recent_thumbs’] : false;echo $before_widget;
// Widget Front End Output
if ( $title ) {
echo $before_title . $title . $after_title;
}$args = array(
‘posts_per_page’ => $recent_posts_number,
‘cat’ => 3,
‘ignore_sticky_posts’ => 1But after loading the widget and saving, all i get is a sentence under the recent posts widget that says “No popular posts available!”
Any ideas?
thanks
The topic ‘How to create a category post widget?’ is closed to new replies.
