php - WP Query Results into 3 lists -


I am trying to run a query that keeps my lists in groups of 3. For example ...

  & lt; Li & gt; & Lt; Div class = "col-md-12" & gt; 1 post & lt; / Div & gt; & Lt; Div class = "col-md-12" & gt; 2 posts & lt; / Div & gt; & Lt; Div class = "col-md-12" & gt; Post 3 & lt; / Div & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; Div class = "col-md-12" & gt; 4 posts & lt; / Div & gt; & Lt; Div class = "col-md-12" & gt; 5 posts & lt; / Div & gt; & Lt; Div class = "col-md-12" & gt; 6 posts & lt; / Div & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; Div class = "colonel-MD-12" & gt; Post 7 & lt; / Div & gt; & Lt; Div class = "col-md-12" & gt; Post 8 & lt; / Div & gt; & Lt; Div class = "col-md-12" & gt; 9 posts & lt; / Div & gt; & Lt; / Li & gt;  

Now, I have the following questions that work, but it seems that sometimes the results show that should each call be one?

  & lt ;? Php $ query = new WP_Query (array ('post_type' = & gt; 'serivces')); ? & Gt; & Lt; Li & gt; & Lt ;? Php $ count = 0; ? & Gt; & Lt ;? While Php ($ query- & quot; is_post ()): $ query- & gt; The_post (); ? & Gt; & Lt; Div class = "col-md-12" & gt; & Lt ;? Php the_title (); ? & Gt; & Lt; / Div & gt; & Lt ;? Php $ count ++; If (($ count% 3) == 0 & amp; amp; amp; amp; $ query-> is_psoz ()) {? & Gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt ;? Php} timeline; ? & Gt; & Lt; / Li & gt;  

Thank you for your help! Cheers.

this $ query-> Is_post () inside the condition (one with the counter) was causing the problem, please call this code & amp; See if it works :)

Edit code

  & lt; Li & gt; & Lt ;? Php $ count = 0; $ Query = new WP_Query (array ('post_type' = & gt; 'serivces')); If ($ query-> is_poz ()): while ($ query- & quot; is_post ()): $ query- & gt; The_post (); If ($ count! = 0 & amp; amp; $ count% 3 == 0) {echo " 
  • }? & Gt; & Lt; Div class = "col-md-12" & gt; & Lt ;? Php the_title (); ? & Gt; & Lt; / Div & gt; & Lt ;? Php $ count ++; Endwhile; end if; ? & Gt; & Lt; / Li & gt;

  • Comments

    Popular posts from this blog

    c# - SignalR: "Protocol error: Unknown transport." when navigating to hub -

    class - Kivy: how to instantiate a dynamic classes in python -

    python - mayavi mapping a discrete colorbar on a surface -