我希望获得主页上显示的图片的永久链接,以便当有人点击图片时重定向到其完整帖子。
add_shortcode( 'zee_recent_works', function( $atts, $content= null ){
ob_start();
$atts = shortcode_atts(array(
'slides' => 2,
'title' => '',
'description' => ''
), $atts);
extract($atts);
$item_per_slide = 4;
$args = array(
'numberposts' => $item_per_slide*$slides,
'orderby' => 'menu_order',
'order' => 'ASC',
'post_type' => 'zee_portfolio'
);
$portfolios = get_posts( $args );
$i = 1;
$j = 1;
$count = count($portfolios);
if ($count>0) {
?>
<div class="col-md-12">
<div id="scroller" class="carousel slide">
<div class="carousel-inner">
<?php
foreach( $portfolios as $key=>$value ) {
if( (($key+1)%($item_per_slide)==0) || $j== $count) {
$lastContainer= true;
} else {
$lastContainer= false;
}
if($i==1){
?>
<div class="item <?php echo ($key==0)? 'active': ''; ?>">
<div class="row">
<?php
}
?>
<div class="col-md-<?php echo round(12/$item_per_slide) ?>">
<div class="portfolio-item">
<div class="item-inner">
<?php
echo get_the_post_thumbnail( $value->ID, array(400,400), array(
'class' => "img-responsive",
'alt' => trim(strip_tags( $value->post_title )),
'title' => trim(strip_tags( $value->post_title ))
));
?>
<h5>
<?php echo $value->post_title; ?>
</h5>
<div class="overlay">
<?php
$full_img = wp_get_attachment_image_src( get_post_thumbnail_id($value->ID), 'full');
$img_src= $full_img[0];
?>
<a class="" title="<?php echo $value->post_title; ?>" href="<?php the_permalink(); ?>" rel="prettyPhoto"></a>
</div>
</div><!--.item-inner-->
</div><!--.portfolio-item-->
</div>
<?php
if(($i == $item_per_slide) || $lastContainer) {
?>
</div><!--/.row-->
</div><!--/.col-xs-->
<?php
$i=0;
}
$i++;
$j++;
}
?>
</div>
</div>
</div><!--/.col-md-12-->
<?php
}
return ob_get_clean();
});
并且链接在那里:
<a class="" title="<?php echo $value->post_title; ?>" href="<?php the_permalink(); ?>" rel="prettyPhoto"></a>
永久链接应该有效,但不起作用。
答案 0 :(得分:1)
您可以尝试the_permalink()
get_permalink($value->ID)
最后一行应该是
<a class="" title="<?php echo $value->post_title; ?>" href="<?php echo get_permalink($value->ID); ?>" rel="prettyPhoto" ></a>
希望有所帮助:)
感谢。