Php 标题上的wordpress特色图像(缩略图)
我正在修复某个人的wordpress站点,我在loop.php和特定页面的模板文件中遇到了这段奇怪的代码。我的目标是将其更改为在标题中显示特色图像。我对如何使用get_缩略图语法输出特色图像进行了一些研究,我通常不会在wordpress的后端/FTP中做太多工作,因此感谢您的帮助和耐心Php 标题上的wordpress特色图像(缩略图),php,wordpress,loops,Php,Wordpress,Loops,我正在修复某个人的wordpress站点,我在loop.php和特定页面的模板文件中遇到了这段奇怪的代码。我的目标是将其更改为在标题中显示特色图像。我对如何使用get_缩略图语法输出特色图像进行了一些研究,我通常不会在wordpress的后端/FTP中做太多工作,因此感谢您的帮助和耐心 <?php /** * @package WordPress * @subpackage WP-Skeleton */ ?> </div> <div id="primary">
<?php
/**
* @package WordPress
* @subpackage WP-Skeleton
*/
?>
</div>
<div id="primary">
<div id="content">
**<?php the_post(); ?>
<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID('full') ), 'page-header' );
$url = $thumb['0'];?>
<div id="page-header" style="background-image:url('<?php echo $url; ?>');">**
</div>
<div style="clear"></div>
<div class="container">
<section class="sixteen columns alpha">
<header class="entry-header">
<h2 class="entry-title">Events</h2>
</header>
<div class="entry-content ">
<?php while ( have_posts() ) : the_post(); ?> <!-- the Loop -->
<article id="post-<?php the_ID(); ?>" class="event">
<div class="title">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title('<h3>', '</h3>'); ?></a> <!--Post titles-->
</div>
<div class="event-img"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('event-img'); ?></a></div>
<?php the_content("Continue reading " . the_title('', '', false)); ?> <!--The Content-->
</article>
<?php endwhile; ?><!-- End the Loop -->
</div>
</section>
<div>
</div> <!-- End two-thirds column -->
</div><!-- End Content -->
</diV>
**
如果要在标题内显示特色图像,请使用下面的代码
<?php
if(have_posts()) :
while (have_posts()) : the_post();
the_post_thumbnail();
endwhile;
endif;
?>
显示的页面是什么问题?这一切看起来都很正常。特色图像(get\u post\u缩略图\u id
)将显示为元素#页眉
的背景图像。使用wp\u get\u attachment\u image\u src
检索此图像的URL。而$thumb['0']
是URL(尽管0不应该使用引号)。感谢您帮助我更好地理解这一点,目前这是循环文件夹,get_post_缩略图也在全宽模板代码中,我认为自定义模板代码用于调用特定的post类。”我还是不知道你在找什么。您的问题是什么?谢谢您的解释,但是如果我想显示页面的特征图像而不是单个帖子,该怎么办。page.php中可以使用相同的代码来获取页面的特征图像。然后我是否需要删除循环/模板文件中的代码?不,可以在循环中显示所有页面/帖子属性。