Hi all. My custom theme is here:
I want to be able to specify a URL that the blue “click here” button in the right sidebar will link to. This value would be different for every post. What is the simplest way to achieve this, particularly so it’s a simple matter of entering the URL somewhere in the admin at the time the post is also made?
Thanks very much for any suggestions!
I would use a Custom Field to hold the URL. When you create a Post, you would add the Custom Field to it and give it the value of the link for that post. Then, in the sidebar, retrieve the custom field for the post and use the value in the link.
Right – Can I access that value from outside the loop though (my sidebar is outside of the loop)?
If you have the post ID, both get_post_meta() and get_post_custom() will work.
Thanks for your help vtxyzzy, I’ve got it to work!
The next step for me is to get the social links for email, facebook and twitter to work. Any idea where I might start?
The solution for those who come after me:
I entered a custom field for the post (name: url, value: URL I want to be displayed outside the loop). I then placed the following in my theme where I want the URL to be:
<?php $url = get_post_meta($post->ID, 'url', true); echo $url; ?>
- The topic ‘Post data in the sidebar’ is closed to new replies.