0

I have this slider on my front page. Right now when I click on an image it goes directly to the permalink and the post. How do I make all the slides go to one specific page?

this is the loop for the slider:

<ul class="tm_magzslider">
    <?php 
    $recent = new WP_Query( array(  "cat" => $tmcategory, 
                                    "posts_per_page" => $tm_totalpost, 
                                    "post_type" => "post", 
                                 ) 
                          ); 
    while($recent->have_posts()) : $recent->the_post(); 
    ?>

        <?php if (has_post_thumbnail()) { ?>        
        <li><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
        <img src="<?php $image_id = get_post_thumbnail_id(); $image_url = wp_get_attachment_image_src($image_id,"img737", true); echo $image_url[0]; ?>" alt="<?php echo get_the_title(); ?>" title="<?php echo get_the_title(); ?>">
        </a></li>       
        <?php } else { ?>       
        <li><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
        <img src="<?php echo get_template_directory_uri(); ?>/images/nophoto515.png" alt="<?php echo get_the_title(); ?>" title="<?php echo get_the_title(); ?>">
        </a></li>
        <?php } ?>

    <?php endwhile; ?>
</ul>

I changed the code to this but still it dosent work?:

<?php if (has_post_thumbnail()) { ?>        
        <li><a href="<?php get_permalink(22); ?>" title="<?php the_title_attribute(); ?>">
        <img src="<?php $image_id = get_post_thumbnail_id(); $image_url = wp_get_attachment_image_src($image_id,"img737", true); echo $image_url[0]; ?>" alt="<?php echo get_the_title(); ?>" title="<?php echo get_the_title(); ?>">
        </a></li>       
        <?php } else { ?>       
        <li><a href="<?php get_permalink(22); ?>" title="<?php the_title_attribute(); ?>">
        <img src="<?php echo get_template_directory_uri(); ?>/images/nophoto515.png" alt="<?php echo get_the_title(); ?>" title="<?php echo get_the_title(); ?>">
        </a></li>
        <?php } ?>

    <?php endwhile; ?>
  • You should be doing the changes in a child theme and not your parent theme. You could use a slider which enables you to add custom url's. – Brad Dalton Apr 25 '14 at 14:21
0

echo get_permalink(123); instead of the_permalink(), provided you know the ID of the "specific page".

the_permalink() will always link to the current post in the Loop, and somewhat nonsensically does not take an ID parameter the way that get_permalink() does.

Reference: https://codex.wordpress.org/Function_Reference/get_permalink

  • i tried changing it but still it dosent work =/ – bear Apr 25 '14 at 14:58
  • Make sure you change the ID-- first parameter-- and make sure you echo the return value of get_permalink(). – s_ha_dum Apr 25 '14 at 17:13
  • I tried this but it dosent work. what is wrong? – bear Apr 28 '14 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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