我创建了一个关系自定义字段(slide_link)来将我的幻灯片链接到页面,但是我很难将链接应用到home.php文件中的滑块按钮。这是我的代码:
<div class="flexslider">
<ul class="slides">
<?php
$query = new WP_Query( array('post_type' => 'slide') );
while ( $query->have_posts() ) : $query->the_post();
?>
<?php
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail_size' );
$url = $thumb['0'];
?>
<?php
global $post;
$meta = get_post_meta( $post->ID );
$captn = isset( $meta['caption'][0] ) ? filter_var( $meta['caption'][0], FILTER_SANITIZE_STRING ) : '';
$slideurl = isset( $meta['slide_link'][0] ) ? filter_var( $meta['slide_link'][0], FILTER_SANITIZE_STRING ) : '';
?>
<li data-thumb="<?php echo $url; ?>">
<img src="<?php echo $url; ?>" />
<p class="flex-caption"> <?php echo($captn); ?> </p>
<a href="<?php echo $slideurl; ?>" class="flex-link">See More</a>
</li>
<?php endwhile; ?>
</ul>
</div><!-- /home banner -->
我在注册自定义字段
的Function.php//function to register vision field
add_filter('the_permalink', 'getCustomFeature6');
function getCustomFeature6($slideurl) {
global $post;
$meta = get_post_meta($post->ID, 'slider_link', true);
return $slideurl;
}
任何帮助将不胜感激!
答案 0 :(得分:0)
我不明白你为什么要使用add_filter('the_permalink', 'getCustomFeature6');
。我会用这个:
<?php $slideurl = get_post_meta($post->ID, "slider_link", true); ?>
<li data-thumb="<?php echo $url; ?>">
<img src="<?php echo $url; ?>" />
<p class="flex-caption"> <?php echo($captn); ?> </p>
<a href="<?php echo $slideurl; ?>" class="flex-link">See More</a>
</li>