2012-02-24 7 views
0

私のウェブサイトでは、custom fieldscustom post typeを作成しました。カスタムフィールドをループに表示する方法を理解しているうちに、the_exceptを使用するWordpressの機能を利用できないことがわかりました。その結果、wordpressのthe_exceptで動作するスライダが空でした。だから、私は自分のカスタムフィールドをthe_contentにfunction.phpを介して直接挿入するという考え方を思いつきました。これはほとんどの場合うまく機能しますが、いくつかの問題があります。私は謝罪しますが、私はPHPであまり進んでいません。答えが単純ならば、許してください。ワードプレスの_contentのカスタマイズ

問題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); 

このコードは前述の例外を除いて実際に機能します。コードに条件文を追加する方法や画像を修正する方法については、誰にも示唆がありますか?

答えて

0

functions.phpにこれを追加しないでください。

コンテンツはある種のページでスチームアウトされます(おそらく現在はsingle.php)、すべてのページに影響を与えるためsingle.phpを編集したくありません。

この例のように、recipesを表示するのはsingleページです。したがって、single.phpを複製してください。ファイルsingle-recipes.phpを呼び出し、そこから作業してください。

ファイル階層の詳細については、http://codex.wordpress.org/Template_Hierarchyをご覧ください。

関連する問題