asadsuman

Short Code Basic And Google Map Shortcode

Mar 20th, 2014
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.10 KB | None | 0 0
  1. <!-----------------------------------------------------Short Code Basic and Google Map Short Code----------------------------------->
  2. <?php
  3. /*
  4. This file contain about Basic and Advance Short code.How to use short code and how it implement this code.
  5.  
  6. */
  7. /*===============================Basic Short Code=========================================*/
  8. function add_basic_shortcode($a,$b=null){
  9. return(<div class="sumon">'.$b.'</div>);
  10.  
  11. }
  12. add_shortcode('add_basic_shortcode','add_basic_shortcode');
  13. /*
  14. Above code Description
  15. 1.At first write a function and give any name that function.
  16. 2.Than I am taking two parameter($a and $b)
  17. 3.$b variable is empty because return $b value
  18. 4.$a this variable specify wordpress content.
  19. */
  20. /*If u want to add images using short code see the blew code */
  21. function add_basic_shortcode($a,$b=null){
  22. return(<img src="'.$b.'" alt="" />);
  23.  
  24. }
  25. add_shortcode('add_basic_shortcode','add_basic_shortcode');
  26. /*=========================Advance Short Code in Wordprss=============================*/
  27. function advance_shortcode($atts,$content=null){
  28. extract(shortcode_atts(array(
  29. 'title'=>'this is title',(/*এই গুলো page and post এর attributes আপনি যত ইচ্ছা তত attribute ব্যবহার করতে পারতে পারেন */)
  30. 'link'=>'#or you give a link',
  31. 'text'=>'this is default text',
  32. 'images'=>'blank or give an images link or location',
  33. 'author_name'=>'here is author name'
  34. )$atts,));
  35. return'<h2>'.$title.'</h2><a href="'.$link.'"></a><p>'.$text.'</p><img src="'.$images.'" alt="" /><h5>'.$author_name.'</h5><div class="sumon">'.$content.'</div>';
  36. }
  37. add_shortcode('advance_shortcode','advance_shortcode');
  38. /*=======================================উপরের code এর বর্ণনা(Advance) ==============================*/
  39. /*
  40. ১. প্রথমে একটা function নিলাম। fucnton এর নাম যা ইচ্ছা তাই নেয়া যাবে।
  41. ২। তারপর add_shortcode করে সেই fucntion কে wordpress এর সাথে hookup(জুড়ে দেয়া হল ) করে দেয়া হল ।
  42. ৩। তারপর extract() function ব্যবহার করা হয়েছে। extract() function এর কাজঃ extract() funcstioটি arry এর element(title,link,text,images,images etc.)value টাকে নিচের variable এর মধ্য ($title,$link,$text,$images,$author_name etc.) নিয়ে দেয় এবং তা print করাতে সাহায্য করে। মোটকথা array মধ্যকার সকল value print করে।
  43. ৪.$atts এই variable টি মুলত wordpress এ content show করাতে handler হিসাবে কাজ করে।
  44. ৫.আমরা যেহেতু function ব্যবহার করেছি সুতরং আমাদেরকে value কে return করাতে হবে। আমরা যে value গুলো দেখাতে চাই তা আমাদের এই return এর মধ্য রাখতে হবে।
  45. ৬। উপরের সব বকবক page and post attributes দেয়ার জন্য
  46. ৭. content add করার জন্য $content যেখানে চাই সেখানে দিতে হবে।
  47. */
  48. /*google map using short code*/
  49. function googe_map($atts,$content=null){
  50. extract(shortcode_atts(array(
  51. 'width'=>'',
  52. 'height'=>'',
  53. 'link'=>'https://maps.google.com/'
  54.  
  55. ),$atts));
  56. return'<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q='.$content.'&amp;aq=&amp;ie=UTF8&amp;hq=&amp;hnear='.$content.'&amp;output=embed"></iframe>';
  57.  
  58. }
  59. add_shortcode( 'googe_map', 'googe_map' );
  60. /*short code for social media*/
  61. function twitter($atts,$content=null){
  62. extract(shortcode_atts(array(
  63. 'data_width'=>'',
  64. 'language'=>'',
  65. 'size'=>'',
  66. 'count'=>'',
  67. 'screen_name'=>'',
  68. 'link'=>''
  69.  
  70. ),$atts));
  71. return'<a href="'.$content.'" class="twitter-follow-button" data-show-count="'.$count.'" data-width="'.$data_width.'" data-lang="'.$language.'" data-size="'.$size.'" data-align="left" data-show-screen-name="'.$screen_name.'">Raihan Webpro @twitter</a>
  72. <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>';
  73.  
  74. }
  75. add_shortcode( 'twitter', 'twitter' );
  76.  
  77. /*facebook like button*/
  78. function fb($atts,$content=null){
  79. extract(shortcode_atts(array(
  80. 'layout'=>'',
  81. 'like'=>'',/*or recommend*/
  82. 'width'=>'',
  83. 'count'=>'',
  84. 'screen_name'=>'',
  85. 'link'=>''
  86.  
  87. ),$atts));
  88. return'<div class="fb-like" data-href="'.$content.'" data-layout="'.$layout.'" data-action="'.$like.'" data-show-faces="true" data-share="true" data-width="'.$width.'"></div>';
  89.  
  90. }
  91. add_shortcode( 'fb', 'fb' );
  92. /*
  93. Above code description
  94. ১. প্রথমে google map থেকে আমি link নিয়ে আসলাম। আপনি যে জায়গার map দেখাতে চান সে জায়গা search করে তার link নিয়ে আসবেন।
  95. তারপর link টি short code এর return এর মাঝে দিয়ে দিবেন । তার পর iframe tag এর class নিয়ে অথবা shortcode এর attributes নিয়ে styleing করতে পারেন।
  96. ২. আপনি যদি চান client short code এর মাঝে সুধু location দিবে আর map চলে আসবে সেই জায়গার , সেক্ষেত্রে
  97. <iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=JHENIDAH,+KHULNA+DIVISION,+BANGLADESH&AMP;AQ=0&AMP;OQ=JHENIDAH&amp;SLL=37.0625,-95.677068&AMP;SSPN=42.174768,56.513672&AMP;ie=UTF8&amp;hq=&amp;hnear=Jhenaidah,+Khulna+Division,+Bangladesh&amp;T=M&AMP;Z=9&AMP;LL=23.475416,89.1706&AMP;output=embed"></iframe>
  98. আপনার location এর নামের জায়গায় (JHENIDAH,+KHULNA+DIVISION,+BANGLADESH&AMP;AQ=0&AMP;OQ=JHENIDAH)sohort code এর $content দিতে হবে।
  99. latitude(t=m&amp;z=9&amp;LL=23.475416,89.1706&AMP;), longitude(SLL=37.0625,-95.677068&AMP;SSPN=42.174768,56.513672&AMP;)বাদ যাবে।
  100. এভাবে short code লিখে wordpress যে পেজ এ location দেখাতে চান সে পেজ এ যাবেন এবং [] এর মাঝে location এর নাম দিলে আপনার location map দেখাবে। []
  101. Dedicated to:Raihan Kabir.
  102. */
  103. ?>
Add Comment
Please, Sign In to add comment