Advertisement
firoze

Promo Shortcode

Jan 13th, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.78 KB | None | 0 0
  1. // Promo Shortcode
  2. function recent_post_shortcode($atts){
  3.    extract(shortcode_atts(array(
  4.       'posts' =>4,
  5.    ), $atts));
  6.  
  7.    $return_string = ''; // wrapper will go here start
  8.    query_posts(array('post_type'=>'frost_promo','posts_per_page'=>4,'order' => 'ASC','showposts' => $posts));
  9.    if (have_posts()) :
  10.       while (have_posts()) : the_post();
  11.       $image = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'promo');
  12.        
  13.          $return_string .= '<div class="promo_option_promo text-center" style="width:270px;float:left;">
  14.                             <img src="'.$image[0].'" alt="'.get_the_title().'" />
  15.                             <h2 class="text-uppercase">'.get_the_title().'</h2>
  16.                             <p>'.get_the_content().'</p>
  17.                             </div>';
  18.       endwhile;
  19.      
  20.         else: // if no post found the above then show here default data
  21.         $return_string .='<div class="error-not-found text-center">Sorry, no portfolio entries for while.</div>'; // this is data end
  22.        
  23.    endif;
  24.    $return_string .= '';  // wrapper will go here end
  25.    wp_reset_query();
  26.    return $return_string;
  27. }
  28.  
  29. add_shortcode('recent-post','recent_post_shortcode');
  30.  
  31.  
  32. // shortcode will be like this
  33. <div class="row">
  34.     <div class="container">
  35.         <div class="col-md-12">
  36.            <?php echo do_shortcode('[recent-post posts=4]');?>
  37.         </div>
  38.     </div>
  39. </div>
  40.  
  41.  
  42.  
  43. // custom post
  44.   // promo area how it works
  45.     register_post_type( 'frost_promo',
  46.     array(
  47.       'labels' => array(
  48.         'name' => __( 'Promos How It works' ),
  49.         'singular_name' => __( 'Promo' ),
  50.         'add_new'=>_('Add New Promo')
  51.       ),
  52.       'public' => true,
  53.        'menu_icon'=> 'dashicons-camera',  /* For Dashicons Menu */
  54.       'has_archive' => true,
  55.       'rewrite'=> array( 'slug' => 'promo' ),
  56.       'supports'=> array( 'title','thumbnail','editor' )
  57.      
  58.     )
  59.   );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement