2010-12-22 11 views
1

저는 PHP에서 꽤 희망이 없기 때문에 약간의 도움을 요청했습니다!여러 워드 프레스 커스텀 포스트 메타 값

저는 WordPress를 daviesmusic.com에 음악 대행사 사이트의 CMS로 사용하고 있으며 사용자 지정 필드를 통해 다양한 아티스트에 대한 추가 정보가 많이 있습니다. 지금까지, 난 그냥과 같이, 사용자 정의 필드가 하나씩 값을 검색했습니다이 잘 작동

<?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; 
    ?> 

로트 : 나는 예를 들어 작가의 사진, 오디오 파일, 오디오 파일의 제목과 너무 같은 오디오 파일에 대한 몇 가지 메모를해야합니다. 값을 검색하는 더 효율적인 방법이 있어야합니다! 어떤 아이디어?

건배

+0

키 배열을 허용하는 함수로 마무리하고 키에 따라 적절한 HTML을 출력합니까? 예를 원하십니까? – t31os

답변

3

here에서이 예를 가지고 : 당신이 가지고있는

$custom_fields = get_post_custom(72); 
$my_custom_field = $custom_fields['my_custom_field']; 
foreach ($my_custom_field as $key => $value){ 
    echo $key . " => " . $value . "<br />"; 
} 

이 예에서 포스트 (ID 번호 (72)에 대한 모든 지정된 사용자 정의 값을 통해이 의지주기, 당신이 얻을 수 있습니다 당신은 $post->ID를 사용하여 귀하의 코드에서). $key을 사용하여 필드 이름을 인쇄하고 $value을 사용하여 해당 필드의 값을 인쇄 할 수 있습니다. if elseif else 문 또는 switch 문을 사용하여 표시 방법을 세분화 할 수 있습니다.

+0

죄송합니다. 답장하는 데 6 개월이 걸렸습니다! 귀하의 답변 주셔서 감사합니다! –