• Resolved tobbger

    (@tobbger)


    I have made a grid on my front page with all post types looping through. There’s an figure with a corresponding class (.news, .project for example) added to each figure. The grid is mixed up with all classes that displays each post-type. .news shows the regular post post-type and .project shows a custom post-type called projekt.

    The grid is structured using Isotope. I now want the grid to load in new entries as I scroll. How would I do this the easiest way? The example with Masonry (related to the Isotope plugin) only shows how to loop through the default post-type.

    Here’s the loop where I want the infinite scroll to happen:

    
    <div class="isotope-container">
    
    <?php query_posts( array('post_type' => array ( 'projekt', 'post', 'instagram', 'medarbetare')));
        while (have_posts()) : the_post();?>
    <!-- begin of loop -->
    <!-- Project post loop -->
        <?php if (get_post_type( $post ) == 'projekt') { ?>
          <figure class="item item-w2 item-h3 project">
              <h3>Projekt</h3><br />
              <h2><a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></h2>
              <div class="bg-img">
                  <div class="overlay"></div>
                  <a href="<?php echo get_permalink(); ?>"><?php the_post_thumbnail(); ?></a>
              </div>
          </figure>
    <!-- Regular post loop -->
        <?php   } else if(get_post_type( $post ) == 'post') { ?>
          <figure class="item item-h2 news">
              <h3>Nyhet</h3>
              <h2><a href="<?php bloginfo('siteurl'); ?>/nyheter/#<?php the_slug();?>"><?php the_title(); ?></a></h2>
              <h3 class="date"><?php the_time( 'Y-m-d' ); ?></h3>
          </figure>
    <!-- Instagram post loop -->
        <?php   } else if(get_post_type( $post ) == 'instagram') { ?>
          <figure class="item item-h2 instagram">
              <h3>Instagram</h3>
              <div class="bg-img">
                  <div class="overlay"></div>
                  <?php the_content(); ?>
              </div>
          </figure>
    <!-- Medarbetare post loop -->
        <?php   } else if(get_post_type( $post ) == 'medarbetare') { ?>
          <figure class="item item-h2 about">
              <h3><a href="<?php bloginfo('template_directory'); ?>/om-oss"><?php the_title(); ?></a></h3>
              <div class="bg-img">
                  <div class="overlay"></div>
                  <img class="portrait" src="<?php the_post_thumbnail_url(); ?>" />
              </div>
          </figure>
        <?php   } ?>
    <?php endwhile; wp_reset_query(); ?>
    <!-- END of loop -->
    
    </div>
    

    Am I missing something?

    • This topic was modified 7 years, 10 months ago by tobbger.
    • This topic was modified 7 years, 10 months ago by tobbger.
    • This topic was modified 7 years, 10 months ago by tobbger.
Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Darren Cooney

    (@dcooney)

    HI tobbger,
    You can build a custom shortcode to include post types of your choosing. You are not limited to standard Posts.
    https://connekthq.com/plugins/ajax-load-more/docs/shortcode-builder/

    Cheers,

    Thread Starter tobbger

    (@tobbger)

    Where do I put the short code?

    Plugin Author Darren Cooney

    (@dcooney)

    Likely directly in your page template, but it sounds like your listing is rather complicated and likely will need some custom development to get it fully working.

    Thread Starter tobbger

    (@tobbger)

    Yeah, there’s one class on the figure for each post-type. Do you have any idea, looking at my code above, what I likely have to do in order to get it working?

    Plugin Author Darren Cooney

    (@dcooney)

    You can get the current post type in a repeater template like so.

    
    global $post;
    $type = get_post_type($post->ID);

    How that helps.

    Thread Starter tobbger

    (@tobbger)

    How would I use that in the snippet I provided?

    I’m sorry. I’m aware that it’s a bit annoying to ask for quick fix and I should definitely have done my research on this and WordPress in general before asking anything. The thing is, I’m doing this site for a client and I’m supposed to deliver the site by this week. Everything basic is working, but the fact that I’m a complete beginner at WordPress makes it very hard for me to work this infinite scroll functionality out by my own. And it’s the only missing piece from getting this done. I’m not expecting anyone to do all of the work for me, but that’s the reason why I’m asking so much in detail – being in a bit of panic and at the same time trying to figure out something I should’ve much more knowledge about before starting. ??

    Plugin Author Darren Cooney

    (@dcooney)

    Yea, I totally get that.

    Your page template:

    <div class="isotope-container">
    <?php echo do_shortcode('[ajax_load_more post_type="projekt, post, instagram, medarbetare"]'); ?>
    </div>

    Your Repeater Template:

    
    <?php 
       global $post;
       $type = get_post_type($post->ID);   
       if ($type == 'projekt') { ?>
       <figure class="item item-w2 item-h3 project">
           <h3>Projekt</h3><br />
           <h2><a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></h2>
           <div class="bg-img">
               <div class="overlay"></div>
               <a href="<?php echo get_permalink(); ?>"><?php the_post_thumbnail(); ?></a>
           </div>
       </figure>
    <!-- Regular post loop -->
     <?php  }else if($type == 'post') { ?>
       <figure class="item item-h2 news">
           <h3>Nyhet</h3>
           <h2><a href="<?php bloginfo('siteurl'); ?>/nyheter/#<?php the_slug();?>"><?php the_title(); ?></a></h2>
           <h3 class="date"><?php the_time( 'Y-m-d' ); ?></h3>
       </figure>
    <!-- Instagram post loop -->
     <?php   } else if($type == 'instagram') { ?>
       <figure class="item item-h2 instagram">
           <h3>Instagram</h3>
           <div class="bg-img">
               <div class="overlay"></div>
               <?php the_content(); ?>
           </div>
       </figure>
    <!-- Medarbetare post loop -->
     <?php   } else if( $type == 'medarbetare') { ?>
       <figure class="item item-h2 about">
           <h3><a href="<?php bloginfo('template_directory'); ?>/om-oss"><?php the_title(); ?></a></h3>
           <div class="bg-img">
               <div class="overlay"></div>
               <img class="portrait" src="<?php the_post_thumbnail_url(); ?>" />
           </div>
       </figure>
     <?php   } ?>
    
    Thread Starter tobbger

    (@tobbger)

    Thank you so much for your help, dcooney! I really, really appreciate it!

    However, the code doesn’t seem to work with the Isotope container. Maybe I need a way to call the event that arranges the figure elements. It works perfectly if I delete the <div class="isotope-container">, but that looks strange ofcourse.

    • This reply was modified 7 years, 10 months ago by tobbger.
    Plugin Author Darren Cooney

    (@dcooney)

    ALM is not going to work out of the box with Isotope, it will take some JaveScript work with Callbacks. Masonry is supported as you see from the examples on the site.

    Good luck.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Adding infinite scroll to Isotope grid with several post types’ is closed to new replies.