php - How i can generate short code of my post -


here custom post code can guide me how can short code want call on home page using avada theme , avada theme using "fusion builer" how can show home page ??

// in "function.php" // testimonial custom post

add_action( 'init', 'create_testimonial' );  function create_testimonial() {     register_post_type( 'testimonial',     array(         'labels' => array(             'name' => 'testimonial',             'singular_name' => 'testimonial',             'add_new' => 'add new',             'add_new_item' => 'add new testimonial',             'edit' => 'edit',             'edit_item' => 'edit testimonial',             'new_item' => 'new testimonial',             'view' => 'view',             'view_item' => 'view testimonial',             'search_items' => 'search testimonial',             'not_found' => 'no movies found',             'not_found_in_trash' => 'no movies found in trash',             'parent' => 'parent testimonial'         ),          'public' => true,         'menu_position' => 15,         'supports' => array( 'title', 'editor', 'comments', 'thumbnail', 'custom-fields' ),         'taxonomies' => array( '' ),         'menu_icon' => plugins_url( 'images/image.png', __file__ ),         'has_archive' => true     ) ); 

}

// in eidtior when calling post

<?php  $query = new wp_query( array('post_type' => 'testimonial', 'posts_per_page' => 4 ) );  while ( $query->have_posts() ) : $query->the_post(); ?>      <div class="post_area">         <div class="post_thumb">             <?php echo the_post_thumbnail(); ?>         </div>         <div class="post_txt">                                     <div class="post_cntnt"><?php the_content(); ?></div>             <div class="post_title"><?php the_title(); ?></div>         </div>         <div class="clear"></div>     </div>   <?php endwhile; ?> 

read shortcode api wordpress codex.

https://codex.wordpress.org/shortcode_api

you need 1 line of code:

add_shortcode( 'testimonial', 'create_testimonial' ); 

put line under function , can use shortcode this:

[testimonial] 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -