カスタムポストコードを使用してWordPressのショートコードを作成する方法。ここで私は、ACFのプラグインといくつかの条件によって生成されたいくつかのカスタムフィールドを持つ:条件付きカスタム投稿を使用してWordPressのショートコードを作成する方法フィールドを取得
<?php
$price = get_field('price',$post->ID);
if(!empty($price)) {
echo get_post_meta($post->ID, 'price', true);
} else {
echo('consult price');
}
wp_reset_query();
?>
私は、このHTMLコードを使用してショートを作成したい:
function Amenities() {
return '<table class="datos-coche table table-bordered">
<tbody>
<tr>
<th scope="col"><img class="aligncenter size-full wp-image-5091" src="http://sitename.com/wp-content/uploads/2012/10/car_icon.png" alt="car_icon" width="30" height="25" /></th>
<th scope="col"><img class="aligncenter size-full wp-image-5095" src="http://sitename.com/wp-content/uploads/2012/10/door_icon.png" alt="door_icon" width="30" height="25" /></th>
<th scope="col"><img class="aligncenter size-full wp-image-5093" src="http://sitename.com/wp-content/uploads/2012/10/user_icon.png" alt="user_icon" width="30" height="25" /></th>
<th scope="col"><img class="aligncenter size-full wp-image-5094" src="http://sitename.com/wp-content/uploads/2012/10/fuel_icon.png" alt="fuel_icon" width="30" height="25" /></th>
<th scope="col"><img class="aligncenter size-full wp-image-5096" src="http://sitename.com/wp-content/uploads/2012/10/transmission_icon.png" alt="transmission_icon" width="30" height="25" /></th>
<th scope="col"><img class="aligncenter size-full wp-image-5092" src="http://sitename.com/wp-content/uploads/2012/10/engine_icon.png" alt="engine_icon" width="30" height="25" /></th>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>';
}
add_shortcode('amenities', 'Amenities');
各td
タグについて、私はいくつかの上に挿入したいですPHPコードget_field()
を使用しています。
私はたくさんの方法を試しましたが、サイトがダウンしました。
私はwordpressを初めて利用しています。
ありがとうございます!
のようなものを試してみてください。私はエコーの下でそれを呼び出す方法を知らない。 –
あなたの提案に応じてコードが正常に動作しています。それをエコーする方法を教えてください。 –