2017-10-17 142 views
0

我寫下面的代碼如下,以顯示我的首頁在WordPress的前3個博客文章。奇怪的代碼添加到自定義功能在wordpress

function wptuts_recentpost($atts, $content=null){ 
$getpost = get_posts(array('number' => 1)); 
$getpost = $getpost[0]; 
$return = "<img src=" . get_the_post_thumbnail($getpost->ID) . " >" . "<br />" . $getpost->post_title . "<br />" . $getpost->post_excerpt . "…"; 
$return .= "<br /><br /><a href='" . get_permalink($getpost->ID) . " style='color: rgb(255, 255, 255); background-color: rgb(117, 172, 255); font-size: 18px; margin: 10px; width: 162px;' class='edgtf-btn edgtf-btn-large edgtf-btn-solid edgtf-btn-custom-hover-bg edgtf-direction-aware-hover'><span class='edgtf-btn-text-holder'><span class='edgtf-btn-text'>read more →</span><div class='edgtf-btn-background-holder'> 
     <span class='edgtf-btn-background' style='background-color: rgb(0, 0, 0); top: 30px; left: 65px;'></span> 
    </div></a>"; 
return $return; 
} 
add_shortcode('newestpost', 'wptuts_recentpost'); 

此代碼用於正常工作,但是當我最近檢查了一遍,永久鏈接這個代碼提供了錯誤的鏈接(部分正確的,但它在最後添加「%20style =」)。

我該如何解決這個問題,以便它能給我提供正確的鏈接。

+0

「風格**刪除風格前的空間** –

回答

3

在這一行:

$return .= "<br /><br /><a href='" . get_permalink($getpost->ID) . " style='color: 

你還沒有把收'href

$return .= "<br /><br /><a href='" . get_permalink($getpost->ID) . "' style='color: 

因爲你還沒有把收',該href解讀開幕'style作爲其收盤價'。因此,您在永久鏈接的末尾獲得%20style=。 只要給你的href關閉'應該已經解決了你的問題。

+1

愚蠢的我...謝謝你的快速回答!問題解決了! –