Wordpress loop grouping

Wordpress loop grouping



I want to loop <li> tag in <ul> tag with continuous numbering but it repeats numbering in each <ul> tag.
here's my code:


<li>


<ul>


<ul>


$catquery = new WP_Query( 'cat=6&posts_per_page=2' );
if ( $catquery->have_posts() )
if ( is_home() && is_front_page() )
while ( $catquery->have_posts() )
$catquery->the_post();
get_template_part( 'template-parts/single-song', get_post_type() );




$catquery = new WP_Query( 'cat=6&posts_per_page=2' );
if ( $catquery->have_posts() )
if ( is_home() && is_front_page() )
while ( $catquery->have_posts() )
$catquery->the_post();
get_template_part( 'template-parts/single-song', get_post_type() );



wp_reset_postdata();



the output is:


<ul>
<li>Post 1</li>
<li>Post 2</li>
</ul>
<ul>
<li>Post 1</li>
<li>Post 2</li>
</ul>



in short my expected output should be like this:


<ul>
<li>Post 1</li>
<li>Post 2</li>
</ul>
<ul>
<li>Post 3</li>
<li>Post 4</li>
</ul>



the template-parts/single-song file contains:


<li></li>






can you show the code of template-parts/single-song template ?

– Ivnhal
Sep 8 '18 at 14:40


template-parts/single-song




1 Answer
1



You should use query pagination or offset. Also, use the array syntax for parameters:



With pagination:


$catquery = new WP_Query(
array(
'cat' => 6,
'posts_per_page' => 2,
'paged' => 2
)
);



With offset:


$catquery = new WP_Query(
array(
'cat' => 6,
'posts_per_page' => 2,
'offset' => 2
)
);



Reference: https://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)