• Resolved paddyinthesun

    (@easylifespain)


    I’m trying to make a homepagebox image link to a page but its not working.

    In home.php, i have defined a custom field:
    < ?php $homepagebox_link = get_post_meta($post->ID, "homepagebox_link", $single = true); ?>
    and then shown the custom field in the link:
    <a href="< ?php echo $homepagebox_link ?>"><img src="<?php echo $thumbnail[0]; ?>" height="150" width="280" title="<?php the_title(); ?>" /></a>

    In the page, i have added a custom field:
    Name: homepagebox_link
    Value: https://www.costacomputer.com/services/

    When i click the image link, it displays www.costacomputer.com/<?php%20echo%20homepagebox_link%20?> in the link rather than the url i have set.

    Hope thats all clear, can anyone help me or point me in the right direction. The site is https://www.costacomputer.com

Viewing 8 replies - 1 through 8 (of 8 total)
  • vtxyzzy

    (@vtxyzzy)

    Do you really have spaces between the opening < and the ?php tags? There should be no spaces there. This: <?php, not this: < ?php

    Thread Starter paddyinthesun

    (@easylifespain)

    I removed the spaces and now the links show as the home page of the website rather than the links i’ve used in the custom field.

    vtxyzzy

    (@vtxyzzy)

    Which page, and where on the page are the links shown?

    Thread Starter paddyinthesun

    (@easylifespain)

    There are 3 custom field links on the home page, one for each homepage box.

    For example, the box titled “Data transfer” has a custom field “homepagebox_link” with the value “https://www.costacomputer.com/services/&#8221;.

    I have given all 3 boxes different values for the custom field “homepagebox_link” but when you click on any of the image links, they all link to the home page instead of the link i have allocated.

    Thanks for your input.

    vtxyzzy

    (@vtxyzzy)

    Are the 3 boxes in the main Loop, or is there a second Loop to populate those boxes?

    Can you post a few lines of code showing the beginning of the Loop and including the code used to get the custom field? If it is more than just a few lines, please put the entire template in a pastebin and post a link here.

    Thread Starter paddyinthesun

    (@easylifespain)

    The 3 boxes are in home.php, the code looks like this:

    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large'); ?>
    		<div class="xs-homepage-box">
    			<h2><?php the_title() ?></h2>
                <?php if ($xs_enable_timthumb == "true") { ?>
    <?php $homepagebox_link = get_post_meta($post->ID, 'homepagebox_link', $single = true); ?>
                  <img src="<?php bloginfo('template_directory'); ?>/timthumb/timthumb.php?src=<?php echo $thumbnail[0]; ?>&h=150&w=280" height="150" width="280" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" />
    	    <?php } else { ?>
    
            	<a href="<?php echo $homepagebox_link ?>"><img src="<?php echo $thumbnail[0]; ?>" height="150" width="280" title="<?php the_title(); ?>" /></a>
                <?php } ?>

    vtxyzzy

    (@vtxyzzy)

    I think the problem is that $homepagebox_link is only set if $xs_enable_timthumb is “true”. Try moving that line up above the timthumb test:

    <?php $homepagebox_link = get_post_meta($post->ID, 'homepagebox_link', $single = true); ?>
    
          <?php if ($xs_enable_timthumb == "true") { ?>
             <img src="<?php bloginfo('template_directory'); ?>/timthumb/timthumb.php?src=<?php echo $thumbnail[0]; ?>&h=150&w=280" height="150" width="280" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" />
          <?php } else { ?>
            	<a href="<?php echo $homepagebox_link ?>"><img src="<?php echo $thumbnail[0]; ?>" height="150" width="280" title="<?php the_title(); ?>" /></a>
          <?php } ?>
    Thread Starter paddyinthesun

    (@easylifespain)

    Thank you very much, it works perfectly now.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Custom field url not working’ is closed to new replies.