0

好的,我正在为主页/首页上的每个帖子使用特色图片(F 图片)。它在大多数情况下都有效,但在包含视频的帖子上,我想每次都重复使用相同的 F 图像。

出于某种原因,F 图像在第一次上传时可以正常工作,但是当我尝试在另一个帖子中重复使用相同的图像时,即使没有报告错误,它应该出现在主页上的空间也是空白的。我尝试通过 url 链接并从媒体管理页面中选择所需的图像。

它起作用的唯一方法是上传同一图像的全新实例。那是白痴。必须有某种方法可以重用图像,而无需为我需要使用它的每个帖子重新上传它。一想到我的服务器上有 54 个相同图像的实例,我就感到恶心。是什么赋予了?我是不是很讨厌并忽略了相关的 php 代码?感谢您的所有意见!

这是来自php函数的代码:

<?php
// Make theme available for translation
// Translations can be filed in the /languages/ directory
load_theme_textdomain( 'your-theme', TEMPLATEPATH . '/languages' );

$locale = get_locale();
$locale_file = TEMPLATEPATH . "/languages/$locale.php";
if ( is_readable($locale_file) )
    require_once($locale_file);

// Get the page number
function get_page_number() {
    if ( get_query_var('paged') ) {
        print ' | ' . __( 'Page ' , 'your-theme') . get_query_var('paged');
    }
} // end get_page_number
// Enable post thumbnails
add_theme_support('post-thumbnails');
set_post_thumbnail_size(300, 200, true);
?>

下面是它在 index.php 中的调用方式:

<!-- get the thumbnail -->
<?php
//Get images attached to the post
$img = null;
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'numberposts' => -1,
'order' => 'ASC',
'post_status' => null,
'post_parent' => $post->ID
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
$img = wp_get_attachment_thumb_url( $attachment->ID );
break;
} ?>

<!-- ***** THE ACTUAL IMAGE ***** -->
<span class="the-thumbnail">
  <a href="<?php the_permalink(); ?>">
    <img src="<?php echo $img; ?>" />
  </a>
</span>
<!-- ***** END THE ACTUAL IMAGE ***** -->

<?php }
?>
<!-- end get the thumbnail -->
4

1 回答 1

2

改变你的

<span class="the-thumbnail">
    <a href="<?php the_permalink(); ?>">
        <img src="<?php echo $img; ?>" />
    </a>
</span>

<span class="the-thumbnail">
    <a href="<?php the_permalink(); ?>">
        <?php the_post_thumbnail(); ?>
    </a>
</span>  
于 2012-02-17T20:37:14.823 回答