0
votes

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

1 Answers

2
votes

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