Support

Account

Home Forums Add-ons Repeater Field Link to External URLs?

Solved

Link to External URLs?

  • Hi…Im trying to set up the code so that the_field can link to an external url page.

    For example, I created a field to put the name of the photographer of any feature image that I use within posts….So, i’m required to give them a link back to their URL.

    This is the code I currently have to display this:

    <p class="image_photographer">Image Courtesy of: <?php the_field('image_photographer'); ?></p>

    I have linked to post pages before, but…im not sure how to get this to work for external page urls….also, I would need to make it redirect in popup window…so, it doesn’t take the visitor away from my site.

    Can you please help…i would appreciate it! 🙂

    Thanks!

    • Elliot

    • January 30, 2014 at 10:10 am

    Hi @wpdragon

    In HTML, a link is created via the <a> tag. You need to use it like this:

    
    <a href="<?php the_field('image_photographer'); ?>" target="_blank">Click here</a>
    
    • Elliot

    • January 30, 2014 at 10:11 am

    Hi @wpdragon

    You have tagged this thread with repeater. Is this a sub field? Please specify this in the future.

    if so, you need to use the the_sub_field instead of ‘the_field’

    Thanks
    E

  • Hi @elliot,

    Thanks for the reply!….Actually, that was my fault – the photographer name doesnt use the repeater…Thanks for noticing that.

    Also, I think i need to clarify regarding the URL…I’m actually trying to have the name of the Photographer be a hyperlink to a specified url…Each post may have a different photographer….so, I may have something backwards in how I setup my field and code.

    Currently, in the admin for the post – I have the field to type the name of the photographer, but I assume I also need the option to include a URL associated the name.

    The field type that I am currently using is “Text”.

    Below is an example of the code I am using now, which does make the Photographers name clickable – but, now how do I associate a specific URL?

    I left a gap in the code on purpose, coz I assume that is where I fill in the missing code…right?

    <p class="image_photographer">Image Courtesy of: <a href="[URL FIELD CODE GOES HERE]; ?>" target="_blank"><?php the_field('image_photographer'); ?></a>

    Hopefully, you can see what I did wrong there, and what im trying to do

    Thanks!

    • James

    • January 30, 2014 at 12:44 pm

    Hi @wpdragon

    something like this

    <p class="image_photographer">Image courtesy of: <a href="<?php the_field('photographer_url')?>"> <?php the_field('image_photographer') ?> </a></p>

    where “photographer_url” is a text field

    Cheers

  • Awesome..it Works!

    Thank you.

  • Hi @elliot — This was solved, but just had one quick question related to this…The code above is working perfectly, but I noticed if I put the Photographers Name, without a URL — the Photographers Name will still be a hyperlink & it will reopen the same post page its on…Is there a way, that if I do not include a URL, that it will only display the Photographer name as plain text, and not as a hyperlink?

    Hope that makes sense. thanks.

    • Elliot

    • February 5, 2014 at 12:32 pm

    Hi @wpdragon

    This is called a conditional statement:

    
    <?php 
    
    $url = get_field('photographer_url');
    
    ?>
    <p class="image_photographer">Image courtesy of: <?php if( $url ): ?><a href="<?php echo $url; ?>"><?php endif; ?> <?php the_field('image_photographer') ?> <?php if( $url ): ?></a><?php endif; ?></p>
    
  • Cool!..Thank you!

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.