• Resolved fath

    (@fath)


    Hi, I’m making a portfolio page for my website. I create a category for Portfolio and using query post to display only portfolio related entries on that page.

    Now the question is, how can i make the post title of each entry to link to my client’s website? Is it possible? Probably using a value defined by custom field?

    Or if there’s any other way please do help.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You could simply link an <h2> tag inside your content and omit the the_title(); from the loop or, as you stated, you could link the the_title() with a custom field.

    You could call your custom field “link” and use it this way:

    <?php $field_name="link"; $field_value = get_post_meta($post->ID, $field_name, true); ?>

    then, to link the title

    <a href="<?php echo $field_value; ?>"><?php the_title(); ?></a>

    This, of course, assumes your “link” custom field contains a fully qualified url.

    Thread Starter fath

    (@fath)

    Hey, it works perfectly. Thanks! ??

    I needed this info for another purpose; great! Thanks.

    Hi All,

    First of all thanks for the helpful post here.
    I am trying to use custom field to change the ‘read more’ links of my posts on the homepage of my blog to link through to either individual pages or to the post page.

    So far I managed to assign the custom fields value (url) to the link of the post but I cannot get the default value back.

    I guess my main problem is letting $field_value be the_permalink() if there is no value in the custom field with the key link
    Please let me know if you have any idea how to fix this.

    What I have:
    an if statement to determine if there is a custom field:
    if($field_name=”link”){
    $field_value = $field_value = get_post_meta($post->ID, $field_name, true);
    }else {
    $field_value = the_permalink();
    }

    The value of $field_value is being read out in the link:
    “<?php echo $field_value; ?>”

    I think this is the answer to your question?

    I have got this, so only if I assign a url to a custom field called “alamy” does the whole thing show up:

    <?php if(get_post_meta($post->ID, "alamy", true)): { ?>
    
                <?php $field_name="alamy"; $field_value = get_post_meta($post->ID, $field_name, true); ?>
                <a href="<?php echo $field_value; ?>" target="_blank">Buy this image at Alamy</a>
                <?php ; } endif ?>

    It seems to work. Thanks for the solution in this post. It saved me a whole afternoon. Or it would have if I’d found it earlier!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Fetch links from custom field’ is closed to new replies.