WordPress.org

Ready to get started?Download WordPress

Forums

Post data in the sidebar (6 posts)

  1. Nick5a1
    Member
    Posted 4 years ago #

    Hi all. My custom theme is here:

    http://rewardsforresearch.com/index2.php/aus/sa/sciatica-clinical-trial-medication-may-provide-pain-relief-not-accomplished-by-current-treatments/

    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!

    Nick

  2. vtxyzzy
    Member
    Posted 4 years ago #

    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.

  3. Nick5a1
    Member
    Posted 4 years ago #

    Right - Can I access that value from outside the loop though (my sidebar is outside of the loop)?

  4. vtxyzzy
    Member
    Posted 4 years ago #

    If you have the post ID, both get_post_meta() and get_post_custom() will work.

  5. Nick5a1
    Member
    Posted 4 years ago #

    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; ?>

  6. vtxyzzy
    Member
    Posted 4 years ago #

    Glad you got that part to work. For the social links, I suggest you start a new thread because many people look for a thread with no replies. If you do that, please use the dropdown at top right to mark this topic 'Resolved'.

Topic Closed

This topic has been closed to new replies.

About this Topic