【问题标题】:Wordpress Custom FieldWordPress 自定义字段
【发布时间】:2010-03-26 19:27:52
【问题描述】:

我想使用 wordpress 的自定义字段为我的网站设置不同的标题横幅,这是我的代码:

<?php

get_header(); ?>

        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
       <div id="BodyWrap">

<!--MAIN CONT-->
<div id="mainCont">
<?php get_sidebar(); ?>
<div id="rotateBanner"><?php 
        // check for image
        $image = get_post_meta($post->ID, 'image', $single = true);?>


        <img class="mainImg" src="<?php bloginfo(template_url); echo $image; ?>" alt=""/>
       </div>

        <div id="mainCopy">
        <div id="content">
        <h2><?php single_post_title(); ?></h2>
                <?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>

                <?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>

    </div>
</div>
</div>
</div>
        <?php endwhile; endif; ?>

    <?php get_footer(); ?>

现在代码呈现,但由于某种原因,它只将 img 路径呈现为:

<img alt="" src="http://www.testground.idghosting.com/philcom/wp-content/themes/phil"/>

here 是演示站点

我在自定义字段中输入了这个:图片 对于我输入的值:/images/sampleHead.png

【问题讨论】:

    标签: php wordpress loops wordpress-theming


    【解决方案1】:

    使用 php 代码尝试过,但有一个插件做得很好,尝试一下http://wordpress.org/extend/plugins/custom-field-images

    【讨论】:

      【解决方案2】:

      我认为您只是缺少一个“/” - 如果您查看下面的代码(wordpress 中制作图像的正常方式):&lt;img src="&lt;?php bloginfo('stylesheet_directory'); ?&gt;/images/logo.png" alt="logo" /&gt;&lt;/div&gt;

      因此你应该有&lt;img class="mainImg" src="&lt;?php bloginfo(template_url); ?&gt;/&lt;?php echo $image; ?&gt; 或类似这种情况,因为我一直无法测试它。

      【讨论】:

        【解决方案3】:

        您必须确保在您的添加帖子页面中,您正在创建正确的 自定义字段...如果您将自定义字段称为“图像”,并且使用“图像”,则图像中的资本将通过此关闭..

        在自定义字段中,我会插入完整的 URL,直接指向图像.. 这样代码更省事,更容易链接到..

            <div id="rotateBanner">
              <?php $image = get_post_meta($post->ID, 'image', $single = true);?>
              <img class="mainImg" src="<?php echo $image; ?>" alt=""/> 
            </div>
        

        【讨论】:

          【解决方案4】:

          bvandrun 指出,您的图片链接应该是这样的

          <img class="mainImg" src="<?php bloginfo(template_url); ?>/<?php echo $image; ?>
          

          我强烈建议将 MagicFields wordpress 插件用于自定义字段。一旦你设置了一个页面。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2017-11-05
            • 2013-11-25
            • 2017-08-28
            • 2019-11-14
            • 1970-01-01
            • 1970-01-01
            • 2017-10-29
            相关资源
            最近更新 更多