0

Please excuse me for being ignorant. I am currently trying to learn more about PHP and WordPress. This is my first time to post a question on StackExchange.

I found a jQuery plugin for a simple Bootstrap gallery, and I like it. I am trying to make it dynamic so that I can add photos to it using Custom Post Types. I have read the 'The Loop' and 'The Loop In Action' documentation on WordPress.org, as well as scoured the web looking for my answer.

When I press 'next' on my gallery, it skips every other photo. It worked fine before I tried to make it dynamic. A regular <li> of photos works fine.

I am trying to use the_post_thumbnail(); as the photo for the gallery.

What am I doing wrong here:

  <ul class="row no-gutters">
  <?php $loop = new WP_Query( array( 'post_type' => 'photography', 'orderby' => 'post_id', 'order' => 'ASC' ) ); ?>
  <?php while( $loop->have_posts() ) : $loop->the_post(); ?>
    <li id="changeJS" class="col-lg-3 col-md-3 col-sm-4 col-xs-6 gal-list thumbnail">
      <?php the_post_thumbnail(); ?>
    </li>
  <?php endwhile; wp_reset_query(); ?>
  </ul>

If it would help to see my site, it's at: techpresswebdesign.com. If I can't get this to work, I will need to make it a regular static list of photos soon. For what I know, I may be approaching this simple problem completely wrong.

I appreciate your time.

7
  • 1
    The fact that you are creating multiple id="changeJS", which is invalid markup, may be causing trouble. But I am guessing. It looks like the WordPress part of this is working.
    – s_ha_dum
    Nov 3, 2015 at 4:14
  • Thank you for the quick response, s_ha_dum. You're right about me using incorrect markup. I changed the id to a class, and unfortunately I am still having the same problem. Do you think it could have something to do with my functions.php or something? I am baffled.
    – Collin512
    Nov 3, 2015 at 7:37
  • "Do you think it could have something to do with my functions.php or something?" -- Why does everyone want to blame WordPress in some obscure way? NO. Something is wrong with your markup vs. what your script expects-- 95% sure.
    – s_ha_dum
    Nov 3, 2015 at 14:11
  • I am new to this stuff. I know that sometimes you need to manipulate the functions.php file. I am not trying to blame WordPress. Sorry for the ignorant questions. I will research more and try to clean up my markup.
    – Collin512
    Nov 3, 2015 at 14:21
  • My problem is mostly not understanding how WordPress works. I am, in fact, trying to learn. But I thought in the meantime, maybe someone has come across this problem and would know what I am doing wrong.
    – Collin512
    Nov 3, 2015 at 15:07

1 Answer 1

0

Maybe this could be useful.

I used it on my own site to display a list of thumbnails.

 <?php  
    // check if there's a thumbnail
   if ( has_post_thumbnail($post->ID)) {

     //show thumbnail
     echo 'get_the_post_thumbnail($post->ID, 'thumbnail' , array('class' => "img-responsive yourClass"));

   } else { 
     //show another image if there's not a thumb 
     echo '<img class="img-responsive" src="'.get_template_directory_uri().'/MISSING-PHOTOS.jpg">';

    }

   ?>

Hope can help you.

3
  • Thank you, sbOk. I am trying to use what I can from this, and no luck so far. But will definitely update if I find an answer.
    – Collin512
    Nov 3, 2015 at 15:05
  • @Collin512 I read your question again and had a look at your site. I think this isn't a wordpress's related question but related to jquery, and it's not between my skills yet...but look at line 14 & 38 of your photo-gallery.js . I don't know for what reason..but the next button link to the 2 next images. Try replacing "2" with "1". Anyway there's an updated version of this script.
    – sb0k
    Nov 3, 2015 at 16:08
  • 1
    That seems extremely reasonable. Unfortunately, I tried that and mixed and matched the 1 and 2 around, and had no luck. I am probably messing things up elsewhere. It's weird, though, since everything works perfectly when static. Only when I tried using CPT did I have issues with the skipping. I really appreciate you looking into this for me.
    – Collin512
    Nov 3, 2015 at 18:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.