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.

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

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100