【问题标题】:WordPress custom fields outside html labelshtml标签外的WordPress自定义字段
【发布时间】:2015-10-09 18:46:02
【问题描述】:

我使用名为“colaboradores”的高级自定义字段插件创建了一个自定义字段,其中包含字段徽标(图像)、方向(字符串)和地图(图像);

archive-colaboradores.php 中,我调用了 WP_Quer。简而言之,代码是:

<?php
    $args = array(
        'post_type' => 'colaboradores',
        'pagination' => false
    ); ?>

    <?php $the_query = new WP_Query( $args ); ?>

    <?php while ( have_posts() ) : the_post(); ?>

        <?php get_template_part( 'content', 'colaboradores' ); ?>

    <?php endwhile; // end of the loop. ?>

所以在 content-colaboradores.php 中,我使用 the_field() 显示我的自定义字段:

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

<h1 class="entry-title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h1>

<?php $image = get_field( 'logo' ); ?>
<?php echo '<img src="' . $image['url'] . '" >'; ?>

<?php echo '<p>' . the_field('direccion') . '</p>'; ?>

<?php $image = get_field( 'mapa' ); ?>
<?php echo '<img src="' . $image['url'] . '" >'; ?>

</article><!-- #post-## -->

一切都很好,除了方向,它总是在

标记之外用谷歌浏览器检查:

我已经删除了 ' 之前的所有代码。 the_field('方向') 。 '

'; ?> 但问题仍然存在。

你知道为什么会这样吗?谢谢。

【问题讨论】:

  • 感谢您的回答!我ve found the problem: *the_field()* includes the echo: [ACF - the_field](http://www.advancedcustomfields.com/resources/the_field/)[/link], final code which works is:
    `

标签: php wordpress


【解决方案1】:

我不能确定,因为开发工具没有显示任何异常,但可以尝试将 the_field 包装在一些标签中以确保没有异常。

&lt;?php echo '&lt;p&gt;' . strip_tags(trim(the_field('direccion'))) . '&lt;/p&gt;'; ?&gt;

我将条形标签放在那里,因为这通常是为什么 chrome 和其他浏览器会将内容放在像 p 标签这样的内联标签之外的原因

除此之外,也许尝试让 wordpress 格式化段落标签,然后看看它是否运行

&lt;?php echo apply_filters("the_content",get_field('direccion')); ?&gt;

看看它们中的任何一个是否有效?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多