• Resolved johndoe01

    (@johndoe01)


    Hello. Around a year ago i have made this post.
    https://wordpress.org/support/topic/split-displayed-results/

    Back then i had no good understanding of WPAdverts internal mechanics, and my client out of the blue wanted again the option to place a featured ad each determined number of ads.

    I placed the code of that post that was:

    <?php
    global $ad_index;
    if( $ad_index = null ) {
      $ad_index = 1;
    }
    
    if( $ad_index % 3 == 0 ) {
      echo "<div>[FEATURED AD]</div>";
    }
    
    include_once ADVERTS_PATH . "/templates/list-item.php";
    $ad_index++;
    ?>

    In the list-item.php customized file.

    But the result was not as expected
    https://imgur.com/a/pBaNEt2

    I know that i can set that in the loop for each number i can set something on the loop. Like this example where for a carousel I needed to set an additional counter and once reaches 3 closes the tag and resets such counter.

    <?php if( $loop->have_posts() ): ?>
        <?php 	  $loop_counter = 0; $featempty=0;
    		      $listings =	count($loop->posts); ?>
    	<?php $post_counter = 0; ?>
        <?php $compareb = 0;?>       
        
        <?php
        //Container Height      
            global $heightblock;  
            if($listings <=1){ $heightblock = 206 ;}
            if($listings ==2){ $heightblock = 412 ;}
            if($listings >=3){ $heightblock = 620 ;}
            //echo 'altura'.$heightblock;
        ?>    
        <div class="featuredlist-carousel-vertical adverts-list adverts-bg-hover slider swiper-container">
        
        <div class="swiper-wrapper">    
    
        <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
        
        <?php
            if($listings <=3){ echo '<div class="under3-block">';}else{
            if ($loop_counter ==0){ echo '<div class="swiper-slide">';}
            }
        
            include apply_filters( "adverts_template_load", ADVERTS_PATH . 'templates/list-item.php' );
            
            /*echo '<pre>'.$loop->posts[$loop_counter]->ID.'</pre>';
            global $post_id;
            echo '<pre>'.$post_id.'</pre>';
            echo*/
        
            $loop_counter++;
    		$post_counter++;
            
            if($listings <=3){ echo '</div>';}else{
                if ($loop_counter >=1){ 
                    $loop_counter = 0;
                    echo "</div>";
                }
            }
    		/*if ($post_counter == $listings){
    			echo "</div>";
    		}*/
    		
            
        ?>
    
        <?php endwhile; ?>
        </div>
        <?php if ($columns != 1): ?>
        <div class="swiper-button-next"></div>
        <div class="swiper-button-prev"></div>
        <?php endif; ?>
        <!-- Add Pagination -->
        <div class="swiper-pagination"></div>
        <!-- If we need scrollbar -->
        <div class="swiper-scrollbar"></div>
    
    </div>
    
    <?php else: ?>
        <?php            
        $featempty=1; 
         /*
    <div class="adverts-list-empty"><em><?php _e("There are no Featured+ ads matching your search criteria.", "wpadverts") ?></em></div>  */ ?>
              
    <?php endif; ?>
    
    <?php wp_reset_query(); ?>

    In the list.php in this section i know i can do something similar

    <?php if( $loop->have_posts() ): ?>
            <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
            <?php include apply_filters( "adverts_template_load", ADVERTS_PATH . 'templates/list-item.php' ) ?>
            <?php endwhile; ?>
            <?php else: ?>

    But i’m not sure how to force that a Featured Ad appears, when the list on the shortcode is limited to only normal ads, and if i go for all, the featured ones goes above in a block.

    Thanks in advance, and sorry if i got myself misunderstood.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    from the screenshot, it looks like the result is actually as expected, but the code I posted was just a template that you need to finish, specifically you need to change this line echo "<div>[FEATURED AD]</div>"; to display what you want it to show otherwise it will just print “[FEATURED AD]” every 3 ads.

    Creating a whole code that will do this is far beyond the free support offered here, sorry.

    Thread Starter johndoe01

    (@johndoe01)

    It’s okay, since I was trying to retake the subject of a dead thread. Let me see how can i throw a featured ad to replace it.

    Thread Starter johndoe01

    (@johndoe01)

    Hello. I managed to put the Featured ads each 3 ads.
    Only detail was that i had to place the

    if( $ad_index % 3 == 0 ) {
      echo "<div>[FEATURED AD]</div>";
    }

    on the list.php instead of list-item.php.

    Thanks anyway. Now that i do understand the original answer now it makes more sense.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Featured Ads in the middle of the list’ is closed to new replies.