function custom_testimonial_post_type() {
$labels = array(
'name' => 'Testimonials',
'singular_name' => 'Testimonial',
'menu_name' => 'Testimonials',
'name_admin_bar' => 'Testimonial',
'add_new' => 'Add New',
'add_new_item' => 'Add New Testimonial',
'new_item' => 'New Testimonial',
'edit_item' => 'Edit Testimonial',
'view_item' => 'View Testimonial',
'all_items' => 'All Testimonials',
'search_items' => 'Search Testimonials',
'not_found' => 'No Testimonials found.',
'not_found_in_trash' => 'No Testimonials found in Trash.',
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'testimonials' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'thumbnail' ),
);
register_post_type( 'testimonial', $args );
}
add_action( 'init', 'custom_testimonial_post_type' );
add_shortcode( 'testimonials', 'wpdocs_testimonials_func' );
function wpdocs_testimonials_func( $atts ) {
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'testimonial',
'posts_per_page' => 5, // Number of testimonials per page
'paged' => $paged
);
$testimonial_query = new WP_Query( $args );
if ( $testimonial_query->have_posts() ) :
while ( $testimonial_query->have_posts() ) : $testimonial_query->the_post();
$image_url = get_the_post_thumbnail_url(get_the_ID(), 'full');
endwhile;
// Pagination
$total_pages = $testimonial_query->max_num_pages;
$total_posts = $testimonial_query->found_posts;
$current_post_count = $testimonial_query->post_count;
if ( $total_pages > 1 ) {
echo '<div class="paginationcustom manjeet">';
$current_page = max( 1, get_query_var( 'paged' ) );
echo '<ul class="custom-pagination">';
// Generate pagination links
$pagination_links = paginate_links( array(
'base' => get_pagenum_link( 1 ) . '%_%',
'format' => 'page/%#%',
'current' => $current_page,
'total' => $total_pages,
'prev_text' => '‹', // Previous arrow
'next_text' => '›', // Next arrow
'type' => 'array', // Output as array to customize
));
// Loop through the links and add custom class
foreach ( $pagination_links as $link ) {
if ( strpos( $link, 'current' ) !== false ) {
echo '<li class="active">' . $link . '</li>'; // Add active class
} else {
echo '<li>' . $link . '</li>';
}
}
echo '</ul>';
echo '<div class="results-count">';
echo 'Showing ' . $current_post_count . ' of ' . $total_posts . ' results';
echo '</div>';
echo '</div>';
}
wp_reset_postdata();
else :
echo '<p>no.testimonial found</p>';
endif;
?>
</div>
</div>
<?php }