Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>$counter = 0; $cnt = 0; $parent_pages = $wpdb-&gt;get_results("SELECT * FROM $wpdb-&gt;posts WHERE post_parent = '0' AND ID &lt;&gt; 2 AND post_type = 'page' ORDER BY menu_order", 'OBJECT'); ?&gt; &lt;?php if ( $parent_pages ) : foreach ( $parent_pages as $pageParent ) : setup_postdata( $pageParent ); ?&gt; &lt;?php $counter++; ?&gt; &lt;div class="linkSection"&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="&lt;?php echo get_permalink($pageParent-&gt;ID); ?&gt;"&gt;&lt;?php echo $pageParent-&gt;post_title; ?&gt;&lt;/a&gt;&lt;/a&gt; &lt;/li&gt; &lt;?php $child_pages = $wpdb-&gt;get_results(" SELECT * FROM $wpdb-&gt;posts WHERE post_parent = '".$pageParent-&gt;ID."' AND ID &lt;&gt; 2 AND post_type = 'page' ORDER BY menu_order", 'OBJECT'); // define prefix and postdix for columns (3 in a row display) $pre = '&lt;div class="row_3"&gt;'; $pos = '&lt;/div&gt;'; if ( $child_pages ) { foreach ( $child_pages as $pageChild ) { setup_postdata( $pageChild ); echo (($cnt%3==0 || $cnt==0) ? $pre:''). '&lt;li&gt; &lt;a href=".'get_permalink($pageChild-&gt;ID).'"&gt;'.$pageChild-&gt;post_title.'&lt;/a&gt; &lt;/li&gt;' .(($cnt%3==0 || $cnt==0) ? $pos:''); $cnt++; } $cnt = 0; } ?&gt; &lt;/ul&gt; &lt;/div&gt; &lt;?php endforeach; endif; ?&gt; </code></pre> <p>So what i did? First, i reformat your code. Yes, i know, that WP uses that style, but it is bad readable for me. Than I added prefix\postfix for list of links. And in-loop counter. <br/></p> <p>How it works: in loop we count every iteration with <code>$cnt++;</code>. In every print we check if it is third row or not if yes - we add prefix and postfix to our line.</p> <p>Now u can adjust css-styles for "row_3" to make it 3-in-row display.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload