我在http://www.urbanvision.org.uk/有一个Wordpress托管网站我已经构建了它,一切都像我想要的那样,我对结果感到满意,因为它是我第一个完全构建的Wordpress网站。
我已经陷入了本周初的请求。
我们有一个待售物业页面(http://www.urbanvision.org.uk/services/property-services/properties-for-sale/)此页面上的项目链接到计划和财产详情的PDF下载。但是,我们现在需要添加许多属性,这些属性不是链接PDF而是链接到外部链接。
我遇到的问题是页面模板依赖于插件高级自定义字段管理的自定义字段,上传PDF的字段是文件上载字段,它将获取PDF而不是其他页面或网站的URL。 / p>
我曾尝试将自定义字段切换为网址而不是上传屏幕但由于以下原因而不热衷于此,1)我将返回其他属性并将网址复制到已更改的字段中)同事更新会变得更加困难。
我还尝试引入一个单独的字段,并确定应该引入哪个自定义字段:
如果property_details中存在PDF文件,请将URL拉入PDF。 如果property_details_url中存在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'); ?>">> > 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'); ?>">> > View Details</a></p><br />
<?php } else { ?>
<br /><a href="<?php the_field('property_details'); ?>" target="_blank" title="<?php the_field('property_title'); ?>">> > View Details</a></p><br />
<?php } ?>
我还看过直接从Word数据库正在使用的MySQL数据库,但真的很难让页面显示没有错误。
与往常一样,任何帮助都将不胜感激。
答案 0 :(得分:2)
你在正确的轨道上,但该做的是将你的自定义字段分配给变量。
即:
<?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'); ?>">> > View Details</a></p><br />
<?php } else { ?>
<br /><a href="<?php the_field('property_details'); ?>" target="_blank" title="<?php the_field('property_title'); ?>">> > View Details</a></p><br />
<?php } ?>
希望检查应该很好,property_details_url除了什么都没有,它会显示链接,如果没有,它会显示另一段代码?
玛蒂