1 回答

TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超4個(gè)贊
為什么這個(gè)腳本不顯示任何內(nèi)容?
提供的代碼顯示了幾個(gè)語(yǔ)法錯(cuò)誤,其中最關(guān)鍵的是<?php在 PHP 語(yǔ)句中重新調(diào)用。
如果prijs是放置此短代碼的帖子的良好自定義字段鍵,則它應(yīng)該可以工作。
function showdetails_shortcode( ) {
$post_id = get_the_ID();
//either output the value or let us know the code is working but the value has not been found
$output = get_post_meta( $post_id, 'prijs', true) ? get_post_meta( $post_id, 'prijs', true) : 'NO CUSTOM VALUE FOUND' ;
return $output;
}
add_shortcode('showdetails', 'showdetails_shortcode');
回應(yīng)評(píng)論,這是一個(gè)帶有兩個(gè)字段和表格輸出的版本,請(qǐng)記住,會(huì)有更清晰(更靈活和簡(jiǎn)潔)的方法來(lái)導(dǎo)出變量并為更多字段生成輸出。
function showdetails_shortcode( ) {
$post_id = get_the_ID();
//extract the field values
$field1 = get_post_meta( $post_id, 'prijs', true) ? get_post_meta( $post_id, 'prijs', true) : 'PRIJS NOT FOUND';
$field2 = get_post_meta( $post_id, 'prijs2', true) ? get_post_meta( $post_id, 'prijs2', true) : 'PRIJS2 NOT FOUND';
//prepare html table output
$output = '<table><tbody>';
$output .= '<tr><td>' . $field1 . '</td></tr>';
$output .= '<tr><td>' . $field2 . '</td></tr>';
$output .= '</tbody></table>';
//return the html
return $output;
}
add_shortcode('showdetails', 'showdetails_shortcode');
- 1 回答
- 0 關(guān)注
- 131 瀏覽
添加回答
舉報(bào)