How to create a shortcode for WordPress using a custom post code. Here I have some custom fields generated by ACF plugin and some conditions:
<?php
$price = get_field('price',$post->ID);
if(!$price){
echo('consult price');
} else {
echo get_post_meta($postid, 'price', true);
echo get_field('price', $post->ID);
}
wp_reset_query();
?>
I want to create a shortcode using this HTML code:
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://ift.tt/26NncUG" alt="car_icon" width="30" height="25" /></th>
<th scope="col"><img class="aligncenter size-full wp-image-5095" src="http://ift.tt/1Z5AqpV" alt="door_icon" width="30" height="25" /></th>
<th scope="col"><img class="aligncenter size-full wp-image-5093" src="http://ift.tt/26NndaV" alt="user_icon" width="30" height="25" /></th>
<th scope="col"><img class="aligncenter size-full wp-image-5094" src="http://ift.tt/1Z5AqpW" alt="fuel_icon" width="30" height="25" /></th>
<th scope="col"><img class="aligncenter size-full wp-image-5096" src="http://ift.tt/26Nng6C" alt="transmission_icon" width="30" height="25" /></th>
<th scope="col"><img class="aligncenter size-full wp-image-5092" src="http://ift.tt/1Z5ArKD" 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');
For each td
tag, I want to insert above some PHP code using get_field()
.
I have tried a lot methods, but the site got down.
Please help I am new to wordpress.
Thanks!
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire