June 3, 201016 yr Hello, I'm trying to use the Custom Fields feature of wordpress to output a download link underneath the actual post. I want something like this in my single.php: <div class="download-name"><?php GETNAME ?></div> <div class="download-link"><a href="<?php GETVALUE ?>"><?php GETVALUE ?></a></div> Which I want to output as: Download Link 1: http://www.TheUrlHere.com However, I'm a total newb in php coding so I would like to ask you if you know what code to put instead of GETNAME and GETVALUE to get the actual name and value. I need to use this for all my posts so I can't use a fixed postid in single.php file. FOR THOSE WHO ARE NOT FAMILIAR WITH CUSTOM FIELDS: http://codex.wordpress.org/Custom_Fields Thank you!
June 3, 201016 yr Change the word "downloads" in the (' ') brackets to whatever you've used as your custom field name: foreach(get_post_custom_values('downloads') as $key => $value) echo "Download Link ".($key+1).": <a href=\"$value\" title=\"Download Link ".($key+1)."\">Download</a>"; Not 100% sure this will work for you, but give it a go...
June 3, 201016 yr Author Change the word "downloads" in the (' ') brackets to whatever you've used as your custom field name: foreach(get_post_custom_values('downloads') as $key => $value) echo "Download Link ".($key+1).": <a href=\"$value\" title=\"Download Link ".($key+1)."\">Download</a>"; Not 100% sure this will work for you, but give it a go... I tried your code but it gave me this error inside the page: Warning: Invalid argument supplied for foreach() in /home/*****/public_html/*****/wp-content/themes/*****/single.php on line 42
Create an account or sign in to comment