【发布时间】:2014-09-28 09:32:33
【问题描述】:
我正在修复某人的 wordpress 网站,我在 loop.php 和特定页面的模板文件中遇到了这个奇怪的代码。我的目标是更改它以在标题中显示特色图像。我对如何使用 get_thumbnail 语法输出特色图像进行了一些研究,我通常不会在 wordpress 的后端/FTP 中做太多事情,所以谢谢你的帮助和耐心。
<?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>
【问题讨论】:
-
有什么问题?这一切看起来很正常。特色图像 (
get_post_thumbnail_id) 正在显示为元素#page-header的背景图像。使用wp_get_attachment_image_src检索此图像的 URL。$thumb['0']是 URL(尽管 0 不应使用引号)。 -
感谢您帮助我更好地理解这一点,目前这是循环文件夹,get_post_thumbnail 也在全角模板代码中,并且我假设调用了一个自定义模板代码特定类别的职位。 '事件'
-
我还是不知道你在找什么。你有什么问题?