2012-06-23 115 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

相关问题