2012-06-28 115 views
0

我正在一个wordpress驱动的网站与模板有一个jcycle滑块在首页。我希望在除主页外的所有页面中使用静态横幅。我发现下面我header.php文件的函数:抓取wordpress页面精选图像header.php

<?php else : // NOT front page ?>` 
    <div id="page-content-title"> 
     <div id="page-content-header" class="container_24"> 
      <div id="page-title"> 

如何从PAGE特色图片在这里显示图像?

回答

0

那么开始你可能想要一个特定的图像大小。在你的functions.php文件中使用add_image_size来做到这一点。然后使用wp_image_attachment_src

要获得页面上的图片,做这样的事情:

<?php 
    $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'slider-size'); 
    echo ('<img src="' . $thumbnail[0] . '">'); 
?> 
0

下面的脚本将帮助你获得特色图片后是否有...

query_posts(); 
while (have_posts()) : the_post(); 
$featuredImage = wp_get_attachment_url(get_post_thumbnail_id($post->ID)); 
echo $featuredImage; 
endwhile; 
wp_reset_query(); 
0

我觉得有通过将参数传入post_thumbnail回调来完成此操作的更简单的方法。这是我想出来的。希望这可以帮助。这只会打印精选图像,如果它存在,并将您的标题图像封装在一个div中,以便您可以控制DOM中的位置。

<?php // Loop used to show post-thumbnail as #header-image if it exists 
while (have_posts()) : the_post(); ?> 

      <?php if (has_post_thumbnail()) { ?> 
      <div id="header-image"> 
      <?php the_post_thumbnail('full');?> 
      </div> 

      <?php } else { ?> 

      <?php }?>