Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have an issue that I believe can be solved one of two ways.

I am using Featured Images in posts for content on a home page slider. What I would like to have happen is to have the destination links on click to be custom. Not the post or image URL of the post/featured image being used to feed the slider.

1) I thought I might be able to use the Image URL feature on the image itself, but it turns out the Featured Images will not accept a custom URL. It defaults back to the image path.

2) I have tried using a custom Post Meta field, but my attempts to retrieve that meta have been unsuccessful. I have set a Meta Field with the name "slider-url" and have dropped the path to the desired destination page into the field. I am then using the following code in the loop for the slider (from the WP Codex) in an attempt to pull that value into the href="" <?php echo get_post_meta($post->ID, "slider-url", true); ?>

I am hoping someone might either have a hack for the Featured Image "Image URL" (along with a way to retrieve that URL), or alternately some insight into why my custom post meta might not be working.

Thanks in advance for your time and expertise.

Cheers!

EDIT: Here's the specific block of code. It's contained within the PHP file of the slider plugin.

    <div id="slider">
<?php 
    $category = get_option('wpns_category');
    $n_slices = get_option('wpns_slices');
?>
<?php query_posts( 'cat='.$category.'&posts_per_page=$n_slices' ); if( have_posts() ) : while( have_posts() ) : the_post(); ?>
    <?php if(has_post_thumbnail()) : ?>
    <a href="<?php echo get_post_meta($post->ID, "slider-url", true); ?>" title="<?php the_title(); ?>"> 
        <?php the_post_thumbnail(); ?>
    </a>
    <?php endif ?>
    <?php endwhile; endif;?>
    <?php wp_reset_query();?>
</div>

Additionally, here's a screen capture of the post meta field: http://s.sct.io/Bl6O

Thanks again!

share|improve this question
    
Can we have a look at the block of code you are currently using to get a better idea of what your trying to achieve. –  Ijaas Nov 13 '11 at 1:05
    
@Ijaas -- I've edited my original post to include more info. Thanks! –  John Nov 13 '11 at 1:18
add comment

2 Answers 2

up vote 1 down vote accepted

I cleaned up the code u have given and it should work as you intend.

Let me know if your still having problems.

<div id="slider">
<?php
    $c = get_option('wpns_category');
    $n = get_option('wpns_slices');
    $s = new WP_Query( array( 'cat' => $c, 'posts_per_page' => $n ) );
    if( $s->have_posts() ): while( $s->have_posts() ): $s->the_post(); global $post;
?>
        <?php if(has_post_thumbnail()){ ?>
            <a href="<?php echo get_post_meta($post->ID, "slider-url", true); ?>" title="<?php the_title(); ?>">
                <?php the_post_thumbnail(); ?>
            </a>
        <?php } ?>
    <?php endwhile; endif;?>
</div>
share|improve this answer
    
Worked perfectly. Many kind regards! –  John Nov 13 '11 at 21:00
add comment

I don't get your logic, however I assume you just want to display a post featured image into a slider locate in home page, in this cause, why don't try something simple like this:

  • Create a category for the features images, lets called 'featured', then try this code in the home page:

    <?php query_posts('category_name=featured'); ?> 
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php if(has_post_thumbnail()) : ?>
    <a href="<?php echo get_post_meta($post->ID, "slider-url", true); ?>" title="<?php the_title(); ?>"> 
    <?php the_post_thumbnail(); ?>
    </a>
    <?php endif ?>
    <?php endwhile; endif;?>
    <?php wp_reset_query();?>
    

Let me know if it works ;)

Regards!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.