Title: Problem with custom loop
Last modified: August 22, 2016

---

# Problem with custom loop

 *  Resolved [cochise85](https://wordpress.org/support/users/cochise85/)
 * (@cochise85)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/problem-with-custom-loop/)
 * Hi Darren,
    can you help me with this custom loop? I can’t find the way to make
   it work
 *     ```
       <?php
   
       $blog_layout=returnOptionValue('blog_index_layout');
   
       if(is_home() && $blog_layout=='grid') { ?>
       	<div id="content-wrapper" class="grid-layout">
       <?php } else { ?>
       	<div id="content-wrapper">
       <?php } ?>
   
       	<?php if(is_home()) : ?>
   
       		<section class="pages clearfix">
   
       			<div id="section-title">
       				<?php echo stripslashes(html_entity_decode(returnOptionValue('blog_title'))); ?>
       			</div>
   
       			<?php
   
       			if(is_search()) {
       				get_template_part( 'loop', 'index-regular' );
       			} else {
       				if($blog_layout=='regular') {
       					get_template_part( 'loop', 'index-regular' );
       				} else if($blog_layout=='grid') {
       					get_template_part( 'loop', 'index-grid' );
       				}
       			}
   
       			?>
   
       		</section>
   
       	<?php else :
   
       		if ( have_posts() ) while ( have_posts() ) : the_post();
   
       		$udt_page_meta=get_post_meta($post->ID, '_udt_page_meta', true);
   
       		if(isset($udt_page_meta['background_image']) && $udt_page_meta['background_image']!='') {
       			$fullscreen_background_image=$udt_page_meta['background_image'];
       		}
   
       		?>
   
       		<section class="homepage">
   
       			<!--section title-->
       			<div id="section-title">
       				<h1><?php
       				if(isset($udt_page_meta['display_title']) && $udt_page_meta['display_title']!='') {
       					echo $udt_page_meta['display_title'];
       				} else {
       					the_title();
       				}
       				?></h1>
       			</div>
       			<!--end section title-->
   
       			<?php
       			if($post->post_content!='') { ?>
       				<section class="pages clearfix">
   
       					<?php the_content('',FALSE); ?>
   
       				</section>
       			<?php }
   
       			if(returnOptionValue('front_page_layout')=='portfolio-grid') {
   
       				$my_args_portfolio = array(
       					'post_type' => 'udt_portfolio',
   
       					'posts_per_page' => 5,
       					'orderby' => 'date',
       					'order' => 'DESC',
       					'suppress_filters' => false
       				);
       				$udt_portfolio = get_posts( $my_args_portfolio );
       				$count_udt_portfolio = count($udt_portfolio);
       				$udt_portfolio_counter = 0;
   
       				if($count_udt_portfolio>0) {
   
       					$porfolio_terms = get_terms( 'portfolio_category' );
       					$porfolio_terms_count=0;
   
       					if ( $porfolio_terms && ! is_wp_error( $porfolio_terms ) ) {
   
       						if(returnOptionValue('display_portfolio_filter') == '1') {
   
       							if($post->post_content!='') {
       								echo '<div class="portfolio-filter-wrapper portfolio-filter-wrapper-below-content">';
       							} else {
       								echo '<div class="portfolio-filter-wrapper">';
       							}
   
       							echo '<a href="#" title="All">All</a> / ';
   
       							foreach ( $porfolio_terms as $porfolio_term ) {
       								echo '<a href="'. get_term_link($porfolio_term) .'">name) . '" data-category-slug="' . esc_attr($porfolio_term->slug) . '">' . $porfolio_term->name . '</a>';
       								$porfolio_terms_count++;
       								if($porfolio_terms_count < count($porfolio_terms)) { echo ' / '; }
       							}
   
       							echo '</div>';
   
       						}
   
       					}
   
       					echo '<div id="grid" class="clearfix">';
   
       					foreach ( $udt_portfolio as $udt_project ) {
       						$udt_portfolio_meta=get_post_meta($udt_project->ID, '_udt_portfolio_meta', true);
   
       						$project_terms = get_the_terms( $udt_project->ID, 'portfolio_category' );
   
       						$project_categories='';
       						if ( $project_terms && ! is_wp_error( $project_terms ) ) {
       							$project_categories = array();
       							foreach ( $project_terms as $project_term ) {
       								$project_categories[] = $project_term->slug;
       							}
       							$project_categories = join( " ", $project_categories );
       						}
   
       						$display_media_size='udt-portfolio-thumb-1';
       						$thumb_type='thumb-type-1';
       						if (has_post_thumbnail($udt_project->ID)) {
       							if(isset($udt_portfolio_meta['display_media_size']) && $udt_portfolio_meta['display_media_size']!='') {
       								$display_media_size=$udt_portfolio_meta['display_media_size'];
       								if($display_media_size=='udt-portfolio-thumb-1') {
       									$thumb_type='thumb-type-1';
       								} else if($display_media_size=='udt-portfolio-thumb-2') {
       									$thumb_type='thumb-type-2';
       								} else if($display_media_size=='udt-portfolio-thumb-3') {
       									$thumb_type='thumb-type-3';
       								} else if($display_media_size=='udt-portfolio-thumb-4') {
       									$thumb_type='thumb-type-4';
       								}
       							}
       							$project_thumbnail_id = get_post_thumbnail_id( $udt_project->ID );
       							$image_src=wp_get_attachment_image_src($project_thumbnail_id, $display_media_size);
       							$display_media_caption='';
       							if(isset($udt_portfolio_meta['display_media_caption']) && $udt_portfolio_meta['display_media_caption']!='') {
       								$display_media_caption='data-caption="'.$udt_portfolio_meta['display_media_caption'].'"';
       							}
       							echo '<div class="thumb '.$thumb_type.'" data-project-categories="'.$project_categories.'">
       								<a>ID).'" title="'.esc_attr($udt_project->post_title).'" '.$display_media_caption.'>
       									<img src="'.$image_src[0].'" alt="'.esc_attr($udt_project->post_title).'">
       								</a>
       							</div>';
       						}
       					}
   
       					echo '</div>';
       				}
       			}
   
       		endwhile; // end of the loop. ?>
       		</section>
   
       	<?php endif; ?>
   
       </div>
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [Darren Cooney](https://wordpress.org/support/users/dcooney/)
 * (@dcooney)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/problem-with-custom-loop/#post-5482167)
 * Hi,
    Sorry not sure what you are trying to do? Where is the ajax load more code?
 *  Thread Starter [cochise85](https://wordpress.org/support/users/cochise85/)
 * (@cochise85)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/problem-with-custom-loop/#post-5482178)
 * hi,
    the load more code “[ajax_load_more post_type=”udt_portfolio” scroll=”false”
   button_label=”Load more…”]” is in the page editor. What i’m looking for is what
   put under “repeater template” to make this loop divided into pages. I tried also
   changing `'posts_per_page' => 5,` in `post_number => -1,'` adding the “post per
   page” option in the shortcode but it doesn’t work… thank you
 *  Plugin Author [Darren Cooney](https://wordpress.org/support/users/dcooney/)
 * (@dcooney)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/problem-with-custom-loop/#post-5482187)
 * Right,
    well that’s going to pretty difficult because you have a lot going on
   in this template and I don’t really understand what/where this template is used.
 * Can you contact me at darren.cooney [at] gmail and maybe, with a bit of work,
   I can help you out?

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Problem with custom loop’ is closed to new replies.

 * ![](https://ps.w.org/ajax-load-more/assets/icon-256x256.png?rev=2944639)
 * [Ajax Load More – Infinite Scroll, Load More, & Lazy Load](https://wordpress.org/plugins/ajax-load-more/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ajax-load-more/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ajax-load-more/)
 * [Active Topics](https://wordpress.org/support/plugin/ajax-load-more/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ajax-load-more/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ajax-load-more/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Darren Cooney](https://wordpress.org/support/users/dcooney/)
 * Last activity: [11 years, 4 months ago](https://wordpress.org/support/topic/problem-with-custom-loop/#post-5482187)
 * Status: resolved