2013-04-30 39 views
0

我用twitter按鈕api製作了一個shortcode hook。當我在圖片或內容之後的任何帖子中使用簡碼時,顯示在帖子頂部的按鈕.how如何顯示圖片或帖子內容下方的按鈕?如何在wordpress的帖子結尾處顯示Shortcode鉤子函數

這是要弄清楚的代碼。

function twittershare() 
{ 
    ?> 
     <a href="https://twitter.com/share" class="twitter-share-button" data-lang="en" data-url="<?php echo get_option('option1'); ?>" data-via="<?php echo get_option('option2');?>" data-text="<?php echo get_option('option3'); ?>" data-count="<?php echo get_option('option4'); ?>" data-lang="<?php echo get_option('option5'); ?>" data-counturl="<?php echo get_option('option1'); ?>" >Tweet</a> 
     <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="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script> 
    <?php 
} 

以下是我創建的簡碼。

add_shortcode('share',array('SampleTwitterShare','twittershare')); 

其中:

  • Share是短碼。
  • SampleTwitterShare是類別 的名稱。
  • twittershare是twitter share API的功能。

回答

0

你必須(串連和)回報的HTML在你的短代碼的回調函數,例如:

function twittershare() 
{ 
    $html = ''; 

    $html .= '<a href="https://twitter.com/share" class="twitter-share-button" data-lang="en" data-url="' . get_option('option1') . '" data-via="' . get_option('option2') . '" data-text="' . get_option('option3') . '" data-count="' . get_option('option4') . '" data-lang="' . get_option('option5') . '" data-counturl="' . get_option('option1') . '" >Tweet</a>'; 
    $html .= '<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="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>'; 

    return $html; 
} 
+0

對不起,我是一個新手到php.i PHP的標籤外使用Twitter的東西,那麼如何將輸出保存到一個變量並將其返回。 – sun 2013-04-30 10:07:44

+0

編輯我的答案,試試吧! – diggy 2013-04-30 11:05:05