繁体   English   中英

WordPress将外部URL添加到特色图片

[英]WordPress adding external URL to featured images

我正在尝试在创建帖子时添加特色图片。 当用户单击图像时,它应该重定向到某个外部URL。 我在创建帖子时为重定向URL设置了自定义字段。 但是在哪里添加代码在php文件中进行重定向。 在搜索时我发现了代码

尝试在page.php中找到带有the_post_thumbnail()的行,并在其中添加链接;

例:

从:

<?php the_post_thumbnail(); ?>

至:

<?php $name = get_post_meta($post->ID, 'ExternalUrl', true);
if( $name ) { ?>
<a href="<?php echo $name; ?>"><?php the_post_thumbnail(); ?></a>
<?php } else {
the_post_thumbnail();
} ?>  

但是我没有找到<?php the_post_thumbnail(); ?> <?php the_post_thumbnail(); ?>在page.php或single.php中。 是正确的方法还是其他替代方法?

如果使用默认模板,则将content.php文件放在主题目录中,该文件将博客数据提供给index.php文件以显示博客内容。

<?php get_template_part( 'content', get_post_format() ); ?>

这意味着根据twentytwelve模板的content.php文件。 希望这对您有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM