Home Forums General Issues Link a field to a page or to a category


Link a field to a page or to a category

  • Hi,

    I’m developing a website like a newspaper and I have created a custom field and I display it on Newspaper theme.

    How can I do to link this custom field to a page or to a category?
    here is the link to the website:

    On the first section/block there is a 4 posts grid with a green box in which is displayed the custom field (PAESE, CHIUSI, PITIGLIANO, CITTÀ DELLA PIEVE).
    This custom field represent the location name and it is a simple text field.

    That I would like is to have the possibility to link this location field to a page or to a category, so that when an user click on it goes to the page (or category) of each location.

    Actually this custom field has no link.

    Any suggestion?


  • Did you try using a URL field? Or a text field that you can use to enter a URL?

    You could also have a field that selects an existing category or page… and output the HTML as needed.

    There are a couple different ways to do it… you can choose a field that returns an Object that contains a label and URL… or have two separate fields for that Data for more flexibility. And you can add a 3rd field… a checkbox, asking if the link should open in a new Window..

    Lot of choices.

    Let me know if you need further help.

    p.s. Remember you could use code similar to below to build an anchor tag based on multiple fields:

    <a href="<?php echo get_field('url'); ?>" title="<?php echo get_field('url_title'); ?>"<?php echo get_field('url_new_window'); ?>><?php echo get_field('url_anchor_text'); ?></a>

    The ‘url_new_window’ field can output target=”_blank” (with a leading space if set to TRUE (or checked) )

  • Hi Keith,

    thank you very much for your reply.

    Basically, I haven’t understood which solution you suggest.
    I mean, text field or checkbox…?

    My idea was to use a select field with a dropdown list of locations to choose.
    It is ok that I can choose only one location per post.

    I have already created a select field and I display it on the front end with this code:

    <?php if( get_field(‘paese’, $this->post->ID) ): ?>
    <div class=”block-left”><?php the_field(‘paese’, $this->post->ID); ?></div>
    <?php endif; ?>

    Next step is how can I do to link each location to a page (for example, I could link CHIUSI (SI) to

    Please help…;-)

    Thank you,

  • Hi Pietro,

    Yes… sorry to have thrown so many suggestions to you in my reply. I was just elaborating that there are plenty of choices.

    I took another look at your site… and see where you have the code.

    A simple approach would be to create a second field for the URL. This could be a text field or a URL field.

    Here is how you could modify the code to include the second field’s value:

    <?php if( get_field('paese', $this->post->ID) ) { ?>
    <div class="block-left"><a href="<?php the_field('collegamento', $this->post->ID); ?>"><?php the_field('paese', $this->post->ID); ?></a></div>
    <?php } ?>

    I hope that’s helpful and gets you closer to your goal. Let me know!

  • Hi Keith,

    thank you very much, but I’m a disaster with PHP…
    I hope you can help me with patience!

    I have created an URL field (slug collegamento) and I see that when I edit a post it is displayed in the back end.
    Inside this URL field I have to insert manually the URL.

    Is there a way if I select the paese CHIUSI (SI) to get the link automatically?


  • Hi Keith,

    thank you, I’m going to test…

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

You must be logged in to reply to this topic.