Can I create custom loops in WordPress?« Back to Questions List
YesYou can create anything with WordPress and Export Kit, including custom queries - eg. Featured Posts. You should always follow the WordPress rules when adding custom content, but this is easy to do using our ${code} tag. We are assuming you have read about using WP_Query on WordPress.org Step 1: Create your custom query $argsThis step can be done either in Photoshop or any text editor. Once you have your custom $args you will need to create your base query. Example Base Query
$the_query = new WP_Query( $args );
//Custom Query Loop
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
// -- YOUR PSD CONTENT
endwhile;
endif;
//Always reset
wp_reset_postdata();
Step 2: Split your base queryYou will need to create 2 Text layers in Photoshop and use our ${code} tag to create the custom loop. Add the layers similar to the image above, with your loop content Layer 1: ${code} wp_query open
$the_query = new WP_Query( $args );
//Custom Query Loop
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
Layer 2: ${code} wp_query close
endwhile;
endif;
//Always reset
wp_reset_postdata();
Step 3: Add your custom contentYou can now add your custom loop content normally. Use ${div|post} or ${div|entry} as required, but |
Do you have the right answer? If you do other users will benefit from your contribution, share your knowledge with the community!
New ${query} TagThis tag is for Folders only! We have a new Layer Tag for WordPress and Folders to support WP_Query directly. You can use UsageCreate a folder to contain your elements and add “ Example${query:array('post_type'=>'gallery', 'post__in'=>array(2,5))} |
Share Your Knowledge!
Contribute to the community and help other users to benefit from your answer with experience and knowledge.