私はPHPにかなり絶望的であるため、少し助けを求めたいと思いました。
私はdaviesmusic.comの音楽エージェンシーサイトのCMSとしてWordPressを使用しており、カスタムフィールドを介してさまざまなアーティスト向けの追加情報をたくさん持っています。これまでのところ、次のように、カスタムフィールド値を1つずつ取得しました。
<?php
//audio title
$audio_title = get_post_meta($post->ID, 'audio_name', true);
if ($audio_title) :
?>
<p><?php echo $audio_title; ?></p>
これは正常に機能しますが、すべて異なる出力を必要とするカスタムフィールドがたくさんあるだけです。たとえば、アーティストの写真、オーディオファイル、オーディオファイルのタイトル、オーディオファイルに関するメモがあります。
<?php
//profile image
$profile_pic = get_post_meta($post->ID, 'profileimage', true);
if($profile_pic) :
?>
<img class="post-thumb-single" src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php echo $profile_pic; ?>&a=t&h=278&w=278&zc=1" alt="<?php the_title(); ?>" />
<?php
endif;
//photographer
$photographer = get_post_meta($post->ID, 'photographer', true);
if($photographer) :
?>
<p id="photographer">Photographer: <b><?php echo $photographer; ?></b></p>
<?php
endif;
//audio title
$audio_title = get_post_meta($post->ID, 'audio_title', true);
if ($audio_title) :
?>
<h4 class="nsmb">Audio files</h4>
<p><?php echo $audio_title; ?></p>
<?php
//audio file
$audio = get_post_meta($post->ID, 'audiofile', true);
if ($audio) :
?>
<p class="audio" id="audioplayer_1">Sorry, there was a problem loading the file.</p>
<script>AudioPlayer.embed("audioplayer_1", {soundFile: "<?php echo $audio; ?>"});</script>
<?php
$audio_credits_1 = get_post_meta($post->ID, 'audio_credits_1', true);
if ($audio_credits_1) :
?>
<p class="audio_cred"><?php echo $audio_credits_1; ?></p>
<?php
endif; endif; endif;
?>
たくさんのコード。値を取得するためのより効率的な方法があるはずです!何か案は?!
乾杯