2016-03-31 109 views
0

夥計們我想添加從ouo .io到我的wordpress網站的簡短鏈接。我想要使​​用他們的API:如何將此API添加到WordPress以自動工作?

您還可以使用我們簡單的API來縮短您的鏈接。下面的鏈接 將生成一個新的縮短鏈接並打印出一個空白頁面,很容易將這個API注入到您的應用程序中。

http://ouo.io/api/WYTlzR4X?s=yourdestinationlink.com 

我加入在後通過附加的申請(OP1)鏈接:

<a href="<?php echo get_sub_field('op1'); ?>" rel='nofollow' target="_blank" class="prv"> 

我想這個鏈接短,因爲現在我用它喜歡:

<a href="http://ouo.io/s/WYTlzR4X?s=<?php echo get_sub_field('op1'); ?>" rel='nofollow' target="_blank" class="prawyklik"> 

我得到的是:

http://ouo.io/s/WYTlzR4X?s=https://link-added-to-op1.com 

,我希望它是:

http://ouo.io/39pkesT 

我想隱藏實際的鏈接並顯示短路。請告訴我如何以這種方式工作?

回答

0

只需添加到Chay22的答案,你應該充分利用瞬態所以你」不要經常向URL shortener API發送相同的請求。

// Get our sub field and create an md5 hash 
$sub = get_sub_field('op1'); 
$md5 = md5($sub); 

// Check if the url has been shortened before, if it hasn't... 
if (false === ($url = get_transient('short-' . $md5))) { 

    // Grab the shortened url and save the transient for future use 
    $url = file_get_contents('http://ouo.io/s/WYTlzR4X?s=' . $sub) 
    set_transient('short-'. $md5, $url); 
} 

<a href="<?= $url ?>" rel="nofollow" target="_blank" class="prawyklik"> 
+0

謝謝我的朋友:) – Tomas

0

我敢肯定,這可以用file_get_contents

file_get_contents('http://ouo.io/s/WYTlzR4X?s=https://link-added-to-op1.com'); 

完成因此,它應該是這樣的

<a href="<?php echo file_get_contents('http://ouo.io/s/WYTlzR4X?s='.get_sub_field('op1')); ?>" rel='nofollow' target="_blank" class="prawyklik"> 
+0

非常感謝,只需要使用API​​鏈接 - http://ouo.io/api/ – Tomas

相關問題