my Problem is, like the title say, that i want to display the Download Link to a file only when a file available is…
i dont know where the error is:
<?php $doc = get_post_meta(get_the_ID(), 'wp_custom_attachment', true); ?>
<div id="custom_pdf">
<a href="<?php echo $doc['url']; ?> ">
Download PDF Here
</a>
</div><!-- #custom_pdf -->
This is the normal code.. its work fine, but here it displayed unconditionally… and the Code for conditionally is:
<?php $doc = get_post_meta(get_the_ID(), 'wp_custom_attachment', true); ?>
<? if(strlen(trim(<?php $doc['url'] ?>)) > 0) {
<div id="custom_pdf">
<a href="<?php echo $doc['url']; ?> ">
Download PDF Here
</a>
</div><!-- #custom_pdf -->
} ; ?> // end if
and here is somewhere the error, but i dont know where.
Can someone please help me. Thanks.
Your PHP tags are not correctly placed in your HTML code:
When you switch from HTML to PHP, you need to open a PHP tag
<?php
, and when you switch from PHP to HTML you need to close the PHP tag?>
.You are opening a
<?php
tag when you are already in phpYou might try using the Download Monitor plugin. You can setup display configurations including icons. It has analytics and file swapping. You can also check a Force Download option so that files do not attempt to load into a new browser window.
http://wordpress.org/extend/plugins/download-monitor/