Can I create custom loops in WordPress?« Back to Questions List

Yes

You 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 $args

This 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 query

You 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 between both text layers. This will soon become a Layer Tag with Lightning Storm

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 content

You can now add your custom loop content normally. Use ${div|post} or ${div|entry} as required, but DO NOT add the ${loop} tag - you are already inside a loop!

Added June 3, 2015 3:55 am

Do you have the right answer? If you do other users will benefit from your contribution, share your knowledge with the community!

New ${query} Tag

This tag is for Folders only!

We have a new Layer Tag for WordPress and Folders to support WP_Query directly. You can use ${query:[args]} to generate any custom loop in your design.

Usage

Create a folder to contain your elements and add “${query:[your query]}” to the folder layer name, this will create the required tags to grab content from a post type such as “gallery”… then you can use ${div|posts} to customize your results to display only the post image.

Example

${query:array('post_type'=>'gallery', 'post__in'=>array(2,5))}
Answer by admin
Answered On November 10, 2015 2:58 pm #
Looking for another answer? View other questions in WordPress Text Photoshop Image or get premium support for guaranteed results.
2371 views
1 answer
Last Answered 9 years ago by admin

Recent Answers

asked by nmax
asked by shanrt
asked by Ali Sodikin
[+] View All Recent Questions

Share Your Knowledge!

Contribute to the community and help other users to benefit from your answer with experience and knowledge.