admin管理员组文章数量:1122832
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; ?>
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; ?>
Share
Improve this question
edited Apr 28, 2014 at 13:39
bear
asked Apr 25, 2014 at 11:44
bearbear
131 silver badge6 bronze badges
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. – Brad Dalton Commented Apr 25, 2014 at 14:21
3 Answers
Reset to default 1Here'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; ?>
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
Use echo get_the_permalink($id)
(Your post $id)
Or echo get_the_permalink()
本文标签: postshow to change the permalink to a specific location
版权声明:本文标题:posts - how to change the permalink to a specific location? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736301189a1931092.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论