Title: Shortcode for using The Loop
Last modified: August 24, 2016

---

# Shortcode for using The Loop

 *  [joemoehobo](https://wordpress.org/support/users/joemoehobo/)
 * (@joemoehobo)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/shortcode-for-using-the-loop/)
 * First, thank you for the wonderfull plugin. I have been using it left and right
   for custom html implementation. This time I’m doing something a bit more difficult
   so I decided to use the support to get some help.
 * I’m trying to implement the classic example of the loop:
 *     ```
       <!-- Start the Loop. -->
        <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
   
        	<!-- Test if the current post is in category 3. -->
        	<!-- If it is, the div box is given the CSS class "post-cat-three". -->
        	<!-- Otherwise, the div box is given the CSS class "post". -->
   
        	<?php if ( in_category( '3' ) ) : ?>
        		<div class="post-cat-three">
        	<?php else : ?>
        		<div class="post">
        	<?php endif; ?>
   
        	<!-- Display the Title as a link to the Post's permalink. -->
   
        	<h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
   
        	<!-- Display the date (November 16th, 2009 format) and a link to other posts by this posts author. -->
   
        	<small><?php the_time('F jS, Y'); ?> by <?php the_author_posts_link(); ?></small>
   
        	<!-- Display the Post's content in a div box. -->
   
        	<div class="entry">
        		<?php the_content(); ?>
        	</div>
   
        	<!-- Display a comma separated list of the Post's Categories. -->
   
        	<p class="postmetadata"><?php _e( 'Posted in' ); ?> <?php the_category( ', ' ); ?></p>
        	</div> <!-- closes the first div box -->
   
        	<!-- Stop The Loop (but note the "else:" - see next line). -->
   
        <?php endwhile; else : ?>
   
        	<!-- The very first "if" tested to see if there were any Posts to -->
        	<!-- display.  This "else" part tells what do if there weren't any. -->
        	<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
   
        	<!-- REALLY stop The Loop. -->
        <?php endif; ?>
       ```
   
 * I tried copying and pasting the above code in the PHP section and the ShortCode
   Template section but both failed to yield any results.
 * Would you be kind enough to give me some tips as to how I could go about implementing
   the above loop using this plugin?
 * Warmly
 * [https://wordpress.org/plugins/shortcodes-ui/](https://wordpress.org/plugins/shortcodes-ui/)

Viewing 1 replies (of 1 total)

 *  [GenealogyCoach](https://wordpress.org/support/users/samatva/)
 * (@samatva)
 * [11 years ago](https://wordpress.org/support/topic/shortcode-for-using-the-loop/#post-5965506)
 * Note that the location where you place the shortcode to execute the above is 
   itself inside a loop…. unless you are putting a ‘do_shortcode ‘ call in a template,
   etc.
 * I’m not certain if you can run a loo within a loop, but I’m suspecting *not*.

Viewing 1 replies (of 1 total)

The topic ‘Shortcode for using The Loop’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/shortcodes-ui_dbeef6.svg)
 * [ShortCodes UI](https://wordpress.org/plugins/shortcodes-ui/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/shortcodes-ui/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/shortcodes-ui/)
 * [Active Topics](https://wordpress.org/support/plugin/shortcodes-ui/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/shortcodes-ui/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/shortcodes-ui/reviews/)

## Tags

 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * 1 reply
 * 2 participants
 * Last reply from: [GenealogyCoach](https://wordpress.org/support/users/samatva/)
 * Last activity: [11 years ago](https://wordpress.org/support/topic/shortcode-for-using-the-loop/#post-5965506)
 * Status: not resolved