Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8376573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:27:37+00:00 2026-06-09T15:27:37+00:00

I wanted the below code in a WordPress shortcode so it can be used

  • 0

I wanted the below code in a WordPress shortcode so it can be used like [testimonials], I have tried a lot of times and failed miserably, ideas would be GREATLY appreciated:

<div class="row cols3 testimonials">
<?php $postnum=1; query_posts('post_type=testimonial&showposts=3'); if (have_posts()) $post = $posts[0]; $c=0; while ( have_posts() ) : the_post();?>
<article class="col<?php if($postnum ==1){echo" first";}elseif($postnum==3){echo" last";}?>">
<p><?php echo get_the_content(); ?></p>
<div class="arrow"><div class="tri"></div></div>
<div class="name"><strong><?php global $post;$text = get_post_meta( $post->ID, '_cmb_testominal_author', true );echo $text;?></strong> - <?php global $post;$text = get_post_meta( $post->ID, '_cmb_testominal_company', true );echo $text;?></div>
</article>
<?php $postnum++; endwhile; wp_reset_postdata(); ?>
</div><!-- /Testimonials -->

*UPDATE*

The below code works, I really have no idea how though, I’m not exactly confident to use it because I don’t understand how it works. Any help would be amazing:

<?php
function testimonials_shortcode($atts, $content = null) {
$the_query = new WP_Query();
$the_query->query($atts);
if ($the_query->have_posts()) : while ($the_query->have_posts()) :  
$the_query->the_post(); ob_start(); ?>

<div class="row cols3 testimonials">
<?php $postnum=1; query_posts('post_type=testimonial&showposts=3'); if (have_posts()) $post = $posts[0]; $c=0; while ( have_posts() ) : the_post();?>
<article class="col<?php if($postnum ==1){echo" first";}elseif($postnum==3){echo" last";}?>">
<p><?php echo get_the_content(); ?></p>
<div class="arrow"><div class="tri"></div></div>
<div class="name"><strong><?php global $post;$text = get_post_meta( $post->ID, '_cmb_testominal_author', true );echo $text;?></strong> - <?php global $post;$text = get_post_meta( $post->ID, '_cmb_testominal_company', true );echo $text;?></div>
</article>
<?php $postnum++; endwhile; wp_reset_postdata(); ?>
</div><!-- /Testimonials -->

<?php endwhile; endif; wp_reset_query(); 
$content = ob_get_contents(); ob_end_clean();
return $content;
}

add_shortcode('testimonials', 'testimonials_shortcode');
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:27:39+00:00Added an answer on June 9, 2026 at 3:27 pm

    Here is what you are looking for (minus the post counting). Paste this into you functions.php and use as [testimonials] in the Post Editor, or in directly in templates with <?php echo do_shortcode("[testimonials]");

    function testimonials_function(){ 
    
      ob_start();
      ?>
      <div class="row cols3 testimonials">
      <?php 
    
      $custom_query = new WP_Query( 'post_type=testimonial&posts_per_page=3' );
    
      if($custom_query->have_posts()) :
    
         while ( $custom_query->have_posts() ) : $custom_query->the_post();
         ?>
                <article>
                  <p><?php the_content(); ?></p>
                  <div class="arrow"><div class="tri"></div></div>
                  <div class="name"><strong><?php echo get_post_meta( get_the_id(),'_cmb_testominal_author', true ); ?></strong> - <?php echo get_post_meta( get_the_id(),'_cmb_testominal_company', true ); ?></div>
               </article>   
        <?php       
        endwhile;
    
      endif;
    
      // Reset Post Data
      wp_reset_postdata();
    
      $content =  ob_get_contents();
      ob_clean();
    
      return $content;
    
    }
    
    add_shortcode('testimonials','testimonials_function');
    

    Let me know how it goes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a code below and wanted to know what could be output.What i
I wanted to generate a list view using below code. But after running this
First, I just wanted to say that the below code is working in reality.
In the example below, if client code using GetPeople wanted to print the name
I wanted to implement a Node type like written below but I want to
I wanted a gradient bottom color for a div.Something like as shown in below
I am new to HTML and CSS designs. I have the below code. <html>
i have the following code below but sometime the serving_description tag isn't there. Right
Can someone confirm that the below code definitely removes items from the BlockingCollection foreach
My Friend told me to use HMACSHA256 algo and i have used the below

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.