0

我在http://www.urbanvision.org.uk/有一个由 Wordpress 管理的网站.

我被困在本周初的一个请求上。

我们有一个待售物业页面 (http://www.urbanvision.org.uk/services/property-services/properties-for-sale/) 此页面上的项目链接到 PDF 下载计划和物业详细信息。但是,我们现在需要添加许多属性,这些属性不是链接 PDF,而是链接到外部链接。

我遇到的问题是页面模板依赖于由插件高级自定义字段管理的自定义字段,上传 PDF 的字段是一个文件上传字段,它将采用 PDF 但不是指向另一个页面或站点的 URL。

我试图将自定义字段切换到 URL 而不是上传屏幕,但出于 2 个原因不热衷于此,1)我将返回其他属性并将 url 复制到更改的字段中,2)它变成同事更新有点困难。

我还尝试引入一个单独的 a 字段并确定应该拉入哪个自定义字段:

如果在 property_details 中存在 PDF 文件,请拉入 PDF 的 URL。如果 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 数据库中提取数据,但确实很难让页面正确显示。

与往常一样,我们将不胜感激任何帮助。

4

1 回答 1

2

你在正确的轨道上,但要做的是将你的自定义字段分配给一个变量。

IE:

<?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 有其他东西,它会显示链接,如果没有,它会显示另一段代码?

马蒂

于 2012-06-23T13:24:28.367 回答