我是 Stack overflow 的新手。 首先感谢所有社区接受我的订阅。 我正在构建的网站有一个小问题:
http://gianfabiopezzolla.com/centocelleonline.it
在头版,我有一个 Mansory,用于显示特色图片和标题的最新帖子。
我想为每个特色图片设置一个指向不同页面的自定义链接(例如,第一张特色图片 -> 联系页面)。
我试过下面的代码,但似乎不起作用:
<article id="post-<?php the_ID(the_id_of_post); ?>" <?php post_class(); ?>>
<div class="item-sizer">
<?php if ( has_post_thumbnail() && ( get_theme_mod( 'index_feat_image' ) != 1 ) ) : ?>
<div class="entry-thumb">
<a href="<?php the_permalink(the_id_of_page); ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail('oria-small-thumb'); ?></a>
</div>
<?php endif; ?>
<header class="entry-header blog-entry-header">
<?php the_title( sprintf( '<h1 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink(the_id_of_page) ) ), '</a></h1>' ); ?>
</header><!-- .entry-header -->
</div>
</article><!-- #post-## -->
有人可以帮助我吗?
最佳答案
我认为如果你像这样使用 get_permalink 就可以了
$link = get_the_permalink($page_id);
<div class="entry-thumb">
<a href="<?php echo $link; ?>"> title="<?php the_title(); ?>"><?php the_post_thumbnail('oria-small-thumb'); ?></a>
</div>
其中 $page_id
是您想要的页面的 ID
是因为 the_permalink();
直接回显了
get_permalink();
将返回一个您必须手动回显的值。这就是您的链接未被打印的原因。
希望对您有所帮助,请尝试一下。
关于php - Wordpress - 每个特色图片都有不同的自定义链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36197345/