0
votes

I have created a new post type for testimonials and portfolio. I have created new widget areas,with this

register_sidebar( array( 
    'name'          => __( 'Testimonial Sidebar', 'my-theme' ),
    'description'   => __( 'Testimonial widgets area', 'my-theme' ),
    'id'            => 'sidebar-3',
    'before_widget' => '',
    'after_widget'  => '',
    'before_title'  => '',
    'after_title'   => '',
) );

I have created page sidebar-testimonial.php and call them in single-testimonial.php by get_sidebar('testimonial');

Now my question is, how to create the widget "Recent Testimonials" same as "Recent Post", by dragging it in 'Testimonial sidebar' I can display them in pages.

1
Please check the link (http://www.wpbeginner.com/wp-tutorials/how-to-create-a-custom-wordpress-widget/)nishant
thanks nishant for replying. ya i saw that link before, but how to list out all the recent testimonials..Paraz Ali

1 Answers

0
votes

It is real easy to create your own recent post widget.

Here are the steps:

  1. Copy the default recent posts widget from core which can be found here.

  2. Add all the relevant code for the widget in your functions.php and rename the widget to what ever you like

  3. Register the new widget. You will now see the widget in the backend

  4. Final customization here would be to alter the query inside the widget. All you basically need to do is to add 'post_type' => 'YOUR POST TYPE NAME', to your query arguments on line 702 of the link provided above

YOu can alternatively make use of the filter provided and simply just filter the arguments of the default recent post widget