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; ?>
1
  • 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. Commented Apr 25, 2014 at 14:21

3 Answers 3

1

Here's how you can modify your code to make all slides link to a specific page with ID 22:

Replace this code with your own implementation

<ul class="tm_magzslider">
<?php 
$recent = new WP_Query( array(  "cat" => $tmcategory, 
                                "posts_per_page" => $tm_totalpost, 
                                "post_type" => "post", 
                             ) 
                      ); 
$specific_page_url = get_permalink(22); // Get the permalink for the specific page
while($recent->have_posts()) : $recent->the_post(); 
?>

    <?php if (has_post_thumbnail()) { ?>        
    <li><a href="<?php echo $specific_page_url; ?>" 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 echo $specific_page_url; ?>" 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; ?>
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

3
  • i tried changing it but still it dosent work =/
    – bear
    Commented Apr 25, 2014 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
    Commented Apr 25, 2014 at 17:13
  • I tried this but it dosent work. what is wrong?
    – bear
    Commented Apr 28, 2014 at 13:37
0

Use echo get_the_permalink($id)(Your post $id) Or echo get_the_permalink()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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