• I have a situation where:

    – I need to create a custom link per image on an image gallery. I have created a text field with HTML outputting so that hyperlinks get converted automatically.
    – The user will be populating that field with the link every time a new post is created.
    – I am using a custom post type (post-portfolio).
    – Each post has a cover image that will be a thumbnail when looking at the gallery.
    – Those links will later on be displayed as a link on the thumbnail of the image – not on the image’s lightbox or single-post page.
    – The gallery’s default behavior is to have two font-awesome icons acting as buttons/links: Lightbox view and single post permalink. I have now added a new font awesome link/button to have that text field acting as the link’s target.

    The code on the functions.php:

    `if(function_exists(“register_field_group”))
    {
    register_field_group(array (
    ‘id’ => ‘acf_sponsorer-lank’,
    ‘title’ => ‘Sponsor hyperl?nk’,
    ‘fields’ => array (
    array (
    ‘key’ => ‘field_56ea5ece13165’,
    ‘label’ => ‘Sponsor l?nk till webbsida’,
    ‘name’ => ‘sponsor_lank_till_webbsida’,
    ‘type’ => ‘text’,
    ‘instructions’ => ‘Skriv h?r webbsidan till sponsorn. Om det inte finns n?gon webbsida skriv endast #’,
    ‘required’ => 1,
    ‘default_value’ => ”,
    ‘placeholder’ => ”,
    ‘prepend’ => ”,
    ‘append’ => ”,
    ‘formatting’ => ‘html’,
    ‘maxlength’ => ”,
    ),
    ),
    ‘location’ => array (
    array (
    array (
    ‘param’ => ‘post_type’,
    ‘operator’ => ‘==’,
    ‘value’ => ‘post-portfolio’,
    ‘order_no’ => 1,
    ‘group_no’ => 1,
    ),
    ),
    ),
    ‘options’ => array (
    ‘position’ => ‘normal’,
    ‘layout’ => ‘default’,
    ‘hide_on_screen’ => array (
    ),
    ),
    ‘menu_order’ => 0,
    ));
    }`

    The code on the gallery that shows all thumbnails:

    `$variable = get_field(‘sponsor_lank_till_webbsida’, $post->post-portfolio);

    <div class=”acts”>
    <h3>’.get_the_title().'</h3>
    <a href=”‘.$url.'” title=”‘.get_the_title().'” class=”icon-search” rel=”prettyPhoto[gallery1]”><!—-></a>
    <a href=”‘.the_field(‘sponsor_lank_till_webbsida’, get_option(‘acf_sponsorer-lank’)).'” class=” icon-h-link” target=”_blank”><!—-></a>
    <a href=”‘.get_permalink().'” class=” icon-link”><!—-></a>
    </div>`

    A note on the last bit of code I wrote:

    The <div class="acts"> is inside of PHP tags, so no need to open and close it there.

    Problem:

    The custom field is showing up where on the custom post type page when the admin creates a new post, but the link on the gallery page has no target (the value that the user inserts on the post creation page).

    I have been reading the documentation and trying so many times and so many ways but I cannot seem to make it work. Can please somebody help me?

    https://www.ads-software.com/plugins/advanced-custom-fields/

  • The topic ‘Custom hyperlinks’ is closed to new replies.