【问题标题】:Post thumbnail not working on wordpress theme发布缩略图不适用于 wordpress 主题
【发布时间】:2012-10-11 03:17:43
【问题描述】:

我正在创建自己的自定义 wordpress 主题。

这是我的主题的 index.php 所拥有的:

 <?php while (have_posts()) : the_post(); ?>
        <li id="post-<?php the_ID(); ?>">
            <h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
            </span>
            <?php if ( has_post_thumbnail()) : ?>
                <a href="<?php the_permalink(); ?>" class="thumb"><img src="<?php the_post_thumbnail(); ?>" /></a>
            <?php endif; ?>
            <div class="post">
                <?php get_the_content(400, "Read more"); ?> <a href="<?php the_permalink(); ?>">Read more</a>.
            </div<br/>

我的functions.php文件有这个:

 <?php

 add_theme_support( 'post-thumbnails', array( 'post' ) );
 the_post_thumbnail( array(80,80) );

 ?>

我的网站显示这个(图片无法加载):

 <a href="http://ipadappbuzz.com/?p=1" class="thumb"><img src="<img width="50" height="50" src="http://ipadappbuzz.com/wp-content/uploads/article-new_ehow_images_a00_05_uu_decorate-outdoors-halloween-800x800-50x50.jpg" class="attachment-post-thumbnail wp-post-image" alt="article-new_ehow_images_a00_05_uu_decorate-outdoors-halloween-800x800" title="article-new_ehow_images_a00_05_uu_decorate-outdoors-halloween-800x800" />" /></a>
                            <div class="post">
                 <a href="http://ipadappbuzz.com/?p=1">Read more</a>.

不知道为什么图片源没有正确加载。

【问题讨论】:

    标签: wordpress thumbnails


    【解决方案1】:

    您的问题是您的 img src 属性指向另一个 img 的字符串定义:

    <a href="http://ipadappbuzz.com/?p=1" class="thumb"><img src="<img width="50" height="50" src="http://ipadappbuzz.com/wp-content/uploads/article-new_ehow_images_a00_05_uu_decorate-outdoors-halloween-800x800-50x50.jpg" class="attachment-post-thumbnail wp-post-image" alt="article-new_ehow_images_a00_05_uu_decorate-outdoors-halloween-800x800" title="article-new_ehow_images_a00_05_uu_decorate-outdoors-halloween-800x800" />" /></a>
                                <div class="post">
                     <a href="http://ipadappbuzz.com/?p=1">Read more</a>.
    

    这是违规行:

    <img src="<img width="50" height="50" src="http://ipadappbuzz.com/wp-content/uploads/article-new_ehow_images_a00_05_uu_decorate-outdoors-halloween-800x800-50x50.jpg" class="attachment-post-thumbnail wp-post-image" alt="article-new_ehow_images_a00_05_uu_decorate-outdoors-halloween-800x800" title="article-new_ehow_images_a00_05_uu_decorate-outdoors-halloween-800x800" />" />
    

    它需要更正为以下 - 或类似的东西:

    <img width="50" height="50" src="http://ipadappbuzz.com/wp-content/uploads/article-new_ehow_images_a00_05_uu_decorate-outdoors-halloween-800x800-50x50.jpg" class="attachment-post-thumbnail wp-post-image" alt="article-new_ehow_images_a00_05_uu_decorate-outdoors-halloween-800x800" title="article-new_ehow_images_a00_05_uu_decorate-outdoors-halloween-800x800" />
    

    现在,至于生成这个的代码:

    <a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    

    我不知道the_permalink()the_title_attribute()the_title() 函数是什么,以及您如何定义它们以及它们返回什么。 但是,我怀疑你在某处引入了额外的结束标签

    更新:

    从原始海报更新我的代码来看,我认为你的 PHP 代码应该如下:

    " class="拇指">"

    因为好像 the_post_thumbnail() 正在回显/返回一个 img:

    <img width="50" height="50" src="http://ipadappbuzz.com/wp-content/uploads/article-new_ehow_images_a00_05_uu_decorate-outdoors-halloween-800x800-50x50.jpg" class="attachment-post-thumbnail wp-post-image" alt="article-new_ehow_images_a00_05_uu_decorate-outdoors-halloween-800x800" title="article-new_ehow_images_a00_05_uu_decorate-outdoors-halloween-800x800" />
    

    【讨论】:

    • 我的主题文件中的代码是: " /> 所以它应该像这样解析和加载源代码: 但出于某种奇怪的原因,图像代码会重复并放置自己在我试图找出原因的另一个现有图像代码中。
    • 如果可以的话,你也可以发一下吗?
    • 我按回车键太快了嘿嘿。阅读我的回复。
    • 让它工作.... 我把
    猜你喜欢
    • 1970-01-01
    • 2012-07-14
    • 2011-09-15
    • 1970-01-01
    • 2020-12-24
    • 1970-01-01
    • 2021-01-16
    • 2014-08-12
    • 1970-01-01
    相关资源
    最近更新 更多