douzhaxian1267 2014-12-18 17:56
浏览 80
已采纳

自定义字段的PHP在wordpress中循环后不起作用

I'm a begginer on wordpress and i would like to add html with custom fields after a loop but it doesn't work... Here is my code :

<section id="jm-categorie-3">
    <img class="jm-parallaxe-1" src="<?php the_field('image_parallaxe_1'); ?>" alt="Personnes souriantes">
</section>

<?php /* Catégorie 4 - Programme */  ?> 

<section id="jm-categorie-4">
    <div id="jm-BlocksPinterest" class="jm-programme-global js-masonry" data-masonry-options='{ "columnWidth": 200, "itemSelector": ".item" }'>
    <h2><?php the_field('titre_3'); ?></h2>
    <?php
        // Start the loop
        $query = new WP_Query(array('post_type' => 'programme-2015', 'posts_per_page' => -1)) ;
        if($query->have_posts()) : while($query->have_posts()) : $query->the_post();
    ?>

        <a class="jm-bloc-programme item" href="<?php the_field('url_programme_2015'); ?>">
            <img src="<?php the_field('image_programme_2015'); ?>" alt="<?php the_title(); ?>">
            <span></span>
            <h3><?php the_title(); ?></h3>
            <h4><?php the_field('horaire_programme_2015'); ?></h4>
        </a>

        <?php // script pour le "Pinterest like blocks"?>
        <script src="http://www.blabla.fr/wp-content/themes/test/js/masonry.pkgd.min.js"></script>
        <script>
            var container = document.querySelector('#jm-BlocksPinterest');
            var msnry = new Masonry( container, {
              // options
              columnWidth: 50,
              itemSelector: '.item'
            });
        </script> 
        <?php endwhile;endif; // end the loop  ?>
    </div>
</section>

<?php /* Catégorie 5 - Parallaxe 2 */  ?> 

<section id="jm-categorie-5">
    <img class="jm-parallaxe-2" src="<?php the_field('image_parallaxe_2'); ?>" alt="">
</section>

My question is : Why the "src" in the last image in section "section id="jm-categorie-5" isn't filled with "?php the_field('image_parallaxe_2'); like the other one at beginning of the code (php the_field('image_parallaxe_1');) ?"

In chrome, it renders this :

img class="jm-parallaxe-2" src="" alt=""

Thank you very much for your help !!

  • 写回答

1条回答 默认 最新

  • dp926460 2014-12-18 20:16
    关注

    After a custom query, you need to reset the postdata with.. wp_reset_postdata(). More info in the Codex.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?