2012-06-23 113 views
0

我有一個WordPress的託管網站http://www.urbanvision.org.uk/我已經建立它,一切工作就像我想要它,我很高興的結果,因爲它是我的第一個完全建立的WordPress的網站。如果自定義字段值存在顯示,如果不顯示另一個自定義字段值

我已經陷入了我在本週初的要求。

我們有一個銷售物業頁面(http://www.urbanvision.org.uk/services/property-services/properties-for-sale/)此頁上的項目鏈接到PDF下載的計劃和財產細節。然而,我們現在有一些需要添加的屬性,不是鏈接PDF而是鏈接到外部鏈接。

我遇到的問題是頁面模板依賴於由插件高級自定義字段管理的自定義字段,上傳PDF的字段是文件上傳字段,它將採用PDF而不是另一個頁面或網站的URL。

我試圖將自定義字段切換到一個URL而不是一個上傳屏幕,但不熱衷於這個原因有兩個原因,1)我會回去通過其他屬性,並複製到更改字段的url和2)更新同事變得更加困難。

我也嘗試推出一個獨立的一個領域,找出哪些自定義字段應該被拉:

如果PDF文件存在於property_details在URL中PDF拉。 如果URL中存在property_details_url,則拉入輸入的URL。

每篇文章有兩部分需要鏈接到更多詳細信息(PDF或外部URL)。它們是縮略圖圖像和查看詳細信息鏈接。

我之前(只是鏈接到PDF)有代碼:

<?php 
$featuredPosts = new WP_Query(); 
$featuredPosts->query('showposts=20&cat=13'); 
while ($featuredPosts->have_posts()) : $featuredPosts->the_post(); ?> 

<div class="literaturedescription"> 
<a href="<?php the_field('property_details'); ?>" title="<?php the_field('property_title'); ?>"> 
<img src="<?php the_field('property_thumbnail'); ?>" width="220px" height="150px" alt="<?php the_field('property_title'); ?>" /></a> 
<p><strong><?php the_field('property_title'); ?></strong><br /><?php the_field('property_excerpt'); ?> <span style="color:red;font-weight:bold;"><?php the_field('property_status'); ?></span> 

<br /><a href="<?php the_field('property_details'); ?>" target="_blank" title="<?php the_field('property_title'); ?>">&gt; &gt; View Details</a></p><br /> 

我已經把它改爲(仍然無法得到它的工作)的代碼:

<?php $featuredPosts = new WP_Query(); 
$featuredPosts->query('showposts=20&cat=12'); 
while ($featuredPosts->have_posts()) : $featuredPosts->the_post(); ?> 

<div class="literaturedescription"> 
<a href="<?php the_field('property_details'); ?>" title="<?php the_field('property_title'); ?>"> 
<img src="<?php the_field('property_thumbnail'); ?>" width="220px" height="150px" alt="<?php the_field('property_title'); ?>" /></a> 
<p><strong><?php the_field('property_title'); ?></strong><br /><?php the_field('property_excerpt'); ?> <span style="color:red;font-weight:bold;"><?php the_field('property_status'); ?></span> 


<?php if(get_field('property_details_url')){ ?> 

<br /><a href="<?php the_field('property_details_url'); ?>" target="_blank" title="<?php the_field('property_title'); ?>">&gt; &gt; View Details</a></p><br /> 

<?php } else { ?> 

<br /><a href="<?php the_field('property_details'); ?>" target="_blank" title="<?php the_field('property_title'); ?>">&gt; &gt; View Details</a></p><br /> 

<?php } ?> 

我也看了一下直接從Wordpress正在使用的MySQL數據庫中拉取,但真的很費力地讓頁面無誤地顯示。

一如既往,任何幫助將不勝感激。

回答

2

你在正確的軌道上,但要做的是將你的customfield分配給一個變量。

即:

<?php 
$prop_det_url = get_field('property_details_url'); 
if($prop_det_url!=''){ ?> 

<br /><a href="<?php echo $prop_det_url; ?>" target="_blank" title="<?php the_field('property_title'); ?>">&gt; &gt; View Details</a></p><br /> 

<?php } else { ?> 

<br /><a href="<?php the_field('property_details'); ?>" target="_blank" title="<?php the_field('property_title'); ?>">&gt; &gt; View Details</a></p><br /> 

<?php } ?> 

希望的檢查應罰款的property_details_url有總比沒有其他財產以後,它會顯示該鏈接,如果沒有它會顯示其他的代碼?

馬蒂

+0

工作完美。非常感謝您的幫助 :) – Ben

相關問題