2011-05-15 58 views
0

我試圖輸出演示文稿並下載使用自定義字段的帖子的鏈接(如果需要)。使用WordPress自定義字段獲取值

下面是示例代碼

<?php if(get_post_meta($post->ID, "demo", true) : ?> <a href="<?php the_permalink() ?>" rel="bookmark"> <div class="demo" src="<?php echo get_post_meta($post->ID, "demo", true) ?>" alt="<?php the_title(); ?>" /> </a> <?php endif; ?>

幫助我,什麼作出錯誤與此代碼

+0

什麼問題?什麼不行? – 2011-05-15 20:30:20

回答

1

你在你的if語句缺少一個右括號... 試試這個:

<?php if(get_post_meta($post->ID, "demo", true)) : ?> 
    <a href="<?php the_permalink() ?>" rel="bookmark"> 
     <img class="demo" src="<?php echo get_post_meta($post->ID, "demo", true) ?>" alt="<?php the_title(); ?>" /> 
    </a> 
<?php endif; ?> 
+0

此外,我相信你的div應該是一個img標籤......你可能也想糾正這個問題。 (也在上面編輯) – 2011-05-15 20:32:31