1 回答
TA贡献1831条经验 获得超4个赞
为什么这个脚本不显示任何内容?
提供的代码显示了几个语法错误,其中最关键的是<?php在 PHP 语句中重新调用。
如果prijs是放置此短代码的帖子的良好自定义字段键,则它应该可以工作。
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');
回应评论,这是一个带有两个字段和表格输出的版本,请记住,会有更清晰(更灵活和简洁)的方法来导出变量并为更多字段生成输出。
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 关注
- 148 浏览
添加回答
举报
