[英]why are two paragraphs being added on wordpress custom excerpt function used?
[英]Weird code added to the custom function in wordpress
我在下面編寫了這段代碼,以便在wordpress的首頁上顯示前3個博客文章。
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 =')。
我該如何解決這個問題,以便為我提供正確的鏈接。
在這一行:
$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
加上'
,就可以解決您的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.