对于我的网站我创建了一个custom post type
到custom fields
。虽然我已经想出了如何将自定义字段显示到循环中,但是我发现我无法利用wordpress的能力来使用该表达式,因此我的滑块在wordpress的the_except上运行时是空的。所以我想出了通过function.php将我的自定义字段直接插入到the_content中的想法。这在大多数情况下都很有效,但我遇到了一些困难。我很抱歉,但我不是很先进的PHP。所以如果答案很简单,请原谅。定制wordpress内容
好的,问题1:我无法让我的图像显示。我尝试了几种方法来处理代码,我能做的最好的方式是获取一个URL或一个破碎的图标来显示。
问题2:我想在插入元字段之前显示一些标题,但是我希望它们在元字段的条件具有正值。
function custom_post_type_default_content($content) {
global $post; global $wp_query;
if ($post->post_type == 'recipes') {
$content .=
'<p> <div id="recipe_name"><h1>'.
get_post_meta($post->ID, "recipe_name", true).'
</h1><p></div>
<br />
<p> <div id="recipe_image">
'.get_post_meta($post->ID, 'recipe_image', true).'
<p>
</p></div>
<br />
<p><div id="serves"><b> Serves: </b>'.
get_post_meta($post->ID, "serves", true).'
</p></div>
<br />
<p><div id="prep_time"><b> Preparation Time: </b>'.
get_post_meta($post->ID, "prep_time", true).'
</p></div>
<br />
<p><div id="wpcf-ingredients"><b> Ingredients: </b><br />'.
get_post_meta($post->ID, "wpcf-ingredients", true).'
</p></div>
<br />
<p><div id="wpcf-cooking_instructions"><b> Cooking Instructions: </b><br />'.
get_post_meta($post->ID, "wpcf-cooking_instructions", true).'
</p></div>
<br />
<p><div id="additional_information"><b> Additional Information: </b><br />'.
get_post_meta($post->ID, "additional_information", true).'
</p></div>';}
return $content;
}
add_filter('the_content', 'custom_post_type_default_content', 1);
此代码实际上功能,与上述例外。有没有人有任何建议如何将条件添加到代码或修复图像?