-
AuthorPosts
-
May 22, 2017 at 8:45 pm #797900
I am using the enfold theme for the first time, and I really love this theme.
I see that this theme comes with a feature to display the testimonials. I really like the way the testimonials are being displayed in the default grid layout. But they are all static content.On my website though, I want to have testimonials as a custom post type. I want to display every individual testimonial on its own page when I click on the person’s name, or picture or a Read More link.
I created a custom post type called “Testimonials” using “CPT UI” plugin.
In order to use exactly the same markup and styling that comes with the default testimonials in Enfold theme, I tried creating a shortcode for my custom post type “Testimonials” in function.php.I have a page called Testimonials. On this page I am using the shortcode [testimonials] to display all the testimonials with default pagination. The testimonials are being displayed perfectly fine as I want them to appear. The only problem is that the default numbered pagination is not showing up for some reason.
Following is the code I have written in functions.php file to create the shortcode.
/* SHORT CODE FOR ALL THE TESTIMONIALS */ function all_testimonials_shortcode() { $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; //echo "Page numbers: " . $paged; $loop = new WP_Query( array( 'post_type' => 'testimonials', 'paged' => $paged, 'posts_per_page' => '4', 'paginate' => 'yes', 'use_main_query_pagination' => 'yes' )); if ( $loop->have_posts() ) { $output = ''; while ( $loop->have_posts() ) { $loop->the_post(); $post_thumbnail_id = get_post_thumbnail_id( $post_id ); $testimonial_permalink = get_permalink( $post_id ); $excerpt = get_the_excerpt( $post_id ); $designation = get_field( 'designation' ); $testimonialTitle = get_the_title(); $output .= "[av_testimonial_single limit='1' href=" . $testimonial_permalink . " src=".$post_thumbnail_id ." link='http://' linktext='']"; $output .= $excerpt . "... <a href=" . $testimonial_permalink . ">Read More</a>"; $output .= "<div class='avia-testimonial-meta-mini'>"; $output .= "<div class='avia-testimonial-name'><strong>".$testimonialTitle."</strong></div>"; $output .= "<div class='avia-testimonial-subtitle '>".$designation."</div>"; $output .= "</div>"; $output .= "[/av_testimonial_single]"; } // echo avia_pagination('$loop->max_num_pages', 'nav'); return do_shortcode("[av_testimonials style='grid' columns='2' grid_style='' interval='5' font_color='' custom_title='' custom_content='' admin_preview_bg='']". $output ."[/av_testimonials]"); wp_reset_postdata(); } }; add_shortcode('testimonials', 'all_testimonials_shortcode');
The testimonials are now displayed fine, and they are displayed in this format:
For some reason, the pagination is not showing up. I want the pagination to be displayed like this:
Can someone tell me if I am missing something in my code. Thanks.
May 23, 2017 at 3:23 am #798028Hey guys – Any ideas on this issue? Can someone point me in the right direction?
May 25, 2017 at 7:55 am #799401 -
AuthorPosts
- You must be logged in to reply to this topic.