Advertisement
firoze

Single Shortcode (query) Usages

Dec 13th, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.21 KB | None | 0 0
  1. // Single Shortcode Usages
  2.  
  3. function price_shortcode($atts){
  4.     extract( shortcode_atts( array(
  5.         'category' => '',
  6.         'color' => '', // this has been used for (wrapper) style css
  7.         'count' => '4', // 4 mean only display 4 post this 4 post always default
  8.     ), $atts, 'price_do_shortcode' ) ); // this is for do_shortcode where we have to query(to show post) <?php echo do_shortcode('[price price_do_shortcode="'.get_post_meta($post->ID, 'price_table', true).'"]');
  9.    
  10.     $q = new WP_Query(
  11.         array('posts_per_page' => 4, // 4 mean only display 4 post -1 mean will display all that i post & if use $count will
  12.                     'post_type' => 'price_table', // this is custom type has been shown in CMB + taxonomy + custom-posts.php
  13.                 'price_category' => $category,  // Here (price_category) From Taxonomy 
  14.                         'meta_key'=>'price_order_id_cmd', //here (price_order_id_cmd) is for price order Need to show in  CMB in id
  15.                             'orderby'=>'meta_value_number',  //this is for price order number
  16.                         'order'=>'ASC'  //this is for price order (ASC &DESC)
  17.                                                               // ASC পুরাতন post গুল থেকে দেখাতে শুরু করবে    
  18.                                                               // DESC নতুন post গুল থেকে দেখাতে শুরু করবে                
  19.                                
  20.             )  
  21.         );                                                       
  22.        
  23.        
  24.     $list = '
  25.    
  26.     <style type="text/css">
  27.      // input style css if needed for wrapper mean below (price_table)
  28.      div.price_table div.plan-price {color:'.$color.'}
  29.      div.price_table div.plan.recommended {border-color: '.$color.';}          
  30.      footer.plan-footer a.primary {background:'.$color.';border:none}
  31.     </style>
  32.    
  33.     <div class="price_table" style="margin-right:10px">'; // wrapper will go here
  34.     while($q->have_posts()) : $q->the_post();
  35.         $idd = get_the_ID();
  36.         $price_type = get_post_meta( $idd, 'price_type', true ); // This have to show on (CMB) for id
  37.         $value_dollor = get_post_meta( $idd, 'value_dollor', true );  // This have to show on (CMB) for id
  38.         $price_time = get_post_meta( $idd, 'price_time', true );   // This have to show on (CMB) for id
  39.         $price_link = get_post_meta( $idd, 'price_link', true );    // This have to show on (CMB) for id
  40.         $price_amount = get_post_meta( $idd, 'price_amount', true );   // This have to show on (CMB) for id
  41.         $list .= '
  42.        
  43.         <style type="text/css">
  44.             // input your style css if needed
  45.         </style>
  46.        
  47.         <div class="column_1">
  48.             <ul>
  49.                 <li class="header_row_1 align_center">
  50.                 <div class="pack-title">'.get_the_title().'</div>
  51.                 </li>
  52.                
  53.                 <li class="header_row_2 align_center">
  54.                 <div class="price"><span>'.$value_dollor.' '.$price_amount.'</span></div>
  55.                 <div class="time">'.$price_time.'</div>
  56.                 </li>
  57.                
  58.             '.get_the_content().'
  59.             <li class="row_style_footer_1"><a href="'.$price_link.'" class="buy_now" target="_blank">Sign Up</a></li>
  60.             </ul>
  61.         </div>
  62.         ';        
  63.     endwhile;
  64.     $list.= '</div>'; // wrapper end
  65.     wp_reset_query();
  66.     return $list;
  67. }
  68. add_shortcode('price', 'price_shortcode');   // this is for shortcode & do_shortcode where we have to query(to show post)
  69.  
  70.  
  71. // How we have to show in html page
  72. <?php echo do_shortcode('[price price_do_shortcode="'.get_post_meta($post->ID, 'price_table', true).'"]'); ?>
  73.  
  74. /// <!--here price is shortcode & price_do_shortcode is optional that is wishlist-->
  75. // <!--here price_table is custom post type-->
  76.  
  77. //  Shortcodes Usages rules
  78. // Shortcode এ <?php echo get_template_directory_uri(); ?> এর পরিবরতে '.get_template_directory_uri().'
  79. ব্যবহার করতে হবে |
  80. // For Title
  81. '.get_the_title().'
  82.  
  83. // For Content
  84. '.get_the_content().'
  85.  
  86. // For Others  (This Codes has to use For Showing Custom Meta Box Data & always usages to do dynamic in wrapper data  )
  87. '.$myusages name.'
  88.  
  89. // Shortcode এ <a href="<?php the_permalink();?>"></a> এর পরিবরতে
  90. <a href="'.get_permalink().'"></a>
  91. ব্যবহার করতে হবে |
  92. // shortcode এ Features Images Add করার জন্নে  
  93. $image = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'product_image_size');
  94.  
  95. এবং
  96. <img src="'.$image[0].'" alt="" /> OR Link images এর জন্নে <a href="'.$image[0].'"></a>
  97.  
  98.  
  99.  
  100. ছোট্ট একটা টিপস
  101. =========================
  102.  
  103. শর্টকোডে কাস্টম পোস্ট নেওয়ার সময় get_the_content() ফাংশনকে কল করলে p ট‍্যাগ জেনারেট হয় না, কিন্তু যদি p ট‍্যাগ জেনারেট করতে চাই, তাহলে যেটা করতে হবে:
  104.  
  105. প্রথমে get_the_content() ফাংশনকে ভেরিয়েবলে নিতে হবে
  106.  
  107. $my_p_tag = get_the_content();
  108.  
  109. তারপর যেখানে কনটেন্ট নিব, সেখানে ব‍্যবহার করতে হবে
  110.  
  111. wpautop( $my_p_tag );
  112.  
  113. তাহলে auto p ট‍্যাগ জেনারেট হবে। বিস্তারিত: http://codex.wordpress.org/Function_Reference/wpautop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement