How to add a Custom Field Download Button on WordPress Posts?

Share:
Share

This tutorial will help you add a custom Download Button at the end of any post (or anywhere) you want to display with ability to change the download link with simple custom field. Works best for Websites like Photoshop Tutorials or any site where you provide freebies or download links.

Let’s see hows it done.

First you have to design or get an image from the internet, you want to use as a Download Button. Now we start the coding thing.

Go to your Theme Editor Page “Dashboard > Appearance > Theme Editor” and open Single.php

>Single.php is responsible for displaying your Post Page.

  • Find <?php the_content(); ?> in Single.php. It calls content from the Post.
  • Add the following code after <?php the_content(); ?> code, where you want the download button to display.
<?php if(get_post_meta($post->ID, "download_link", $single = true) != ""){ ?>
 <a href="<?php echo get_post_meta($post->ID, "download_link", $single = true); ?>"<img src="IMG URL" border="0"></a>
 <?php } ?>

If you want to style your Download Image, wrap it with a div and define a custom style which we will later on add to the stylesheet.css of your theme file. (this is totally optional but suggested)

<div id="mydownload">
 <?php if(get_post_meta($post->ID, "download_link", $single = true) != ""){ ?>
 <a href="<?php echo get_post_meta($post->ID, "download_link", $single = true); ?>"<img src="IMG URL" border="0"></a>
 <?php } ?>
 </div>
  • Now after defining the ‘mydownload’ id to the code, lets head over to the stylesheet.css and add some custom styles. This you have to do yourself depending on your theme and stylesheet add padding, margins or whatever you find suitable.
  • Create a new style at the end of style sheet with #mydownload {} and add any styles you want in between the brackets.
  • We added the code to call the custom field in the single.php. Now lets see if this thing works.
  • Go to your Post Page Dashboad > Post > Add New.
  • Scroll down to your custom field box and add a new custom field

Publish and see if your image is showing correctly.

You may have to edit code place or style sheet a couple of times to get some good results depending on your theme.

If you had any problems following this tutorial or any questions, feel free to comment!

Share:
Share

Tags: ,

4 Responses to “How to add a Custom Field Download Button on WordPress Posts?”

  1. Saad 31. Dec, 2009 at 7:26 pm #

    Thanks for the great post.:)
    Saad´s last blog ..How to Download YouTube Videos with Chrome Extensions My ComLuv Profile

    [Reply]

Trackbacks/Pingbacks

  1. Tweets that mention How to add a Custom Field Download Button on Wordpress Posts? -- Topsy.com - 31. Dec, 2009

    [...] This post was mentioned on Twitter by Enk., Paul Sanduleac. Paul Sanduleac said: How to add a Custom Field Download Button on #Wordpress Posts? http://goo.gl/BY2q @WpPanda [...]

  2. uberVU - social comments - 31. Dec, 2009

    Social comments and analytics for this post…

    This post was mentioned on Twitter by enked: How to add a Custom Download Button on WordPress Posts? http://bit.ly/74ce74 #Wordpress…

  3. WordPress Tutorials - 04. Jan, 2010

    How to add a Custom Field Download Button on Posts…

    This tutorial will help you add a custom Download Button at the end of any post (or anywhere) you want to display with ability to change the download link with simple custom field. Works best for Websites like Photoshop Tutorials or any site where you …

Leave a Reply

CommentLuv Enabled