Skip to content

Instantly share code, notes, and snippets.

@ckunte
Created April 2, 2015 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ckunte/8dbd841e65b5655422ca to your computer and use it in GitHub Desktop.
Save ckunte/8dbd841e65b5655422ca to your computer and use it in GitHub Desktop.
Custom articles loop (for WordPress)
<?php
// Begin main loop to list page's static content
?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h2 class="post" id="post-<?php the_ID(); ?>">
<a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
</h2>
<?php the_content('Read on &#155;'); ?>
<?php endwhile; ?>
<?php
// Begin first special loop:
//
// WordPress Articles Loop
// Displays posts that have both the
// following tags: wordpress, articles
?>
<?php $articles_query = new WP_Query('tag=wordpress+articles&showposts=-1');?>
<h2>Articles</h2>
<table>
<?php while($articles_query->have_posts()) : $articles_query->the_post(); ?>
<tr>
<td><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
<?php { the_excerpt(); } ?><span><?php the_category(', ') ?></span></td>
</tr>
<?php endwhile; ?>
</table>
<?php // End first special loop ?>
<?php
// Begin second special loop:
//
// WordPress Themes Loop
// Displays posts that have both the
// following tags: wordpress, themes
?>
<?php // Begin second special loop ?>
<?php $themes_query = new WP_Query('tag=wordpress+themes&showposts=-1');?>
<h2>Themes</h2>
<table>
<?php while($themes_query->have_posts()) : $themes_query->the_post(); ?>
<tr>
<td><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
<?php { the_excerpt(); } ?><span><?php the_category(', ') ?></span></td>
</tr>
<?php endwhile; ?>
</table>
<?php // End second special loop ?>
<?php
// Begin third special loop:
//
// WordPress Code Loop
// Displays posts that have both the
// following tags: wordpress, code
?>
<?php // Begin third special loop ?>
<?php $code_query = new WP_Query('tag=wordpress+code&showposts=-1');?>
<?php // Edit the following title to change if required ?>
<h2>Code and Plugins</h2>
<table>
<?php while($themes_query->have_posts()) : $themes_query->the_post(); ?>
<tr>
<td><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
<?php { the_excerpt(); } ?><span><?php the_category(', ') ?></span></td>
</tr>
<?php endwhile; ?>
</table>
<?php else : ?>
<h2>Not found</h2>
<p><?php _e("Sorry, but you are looking for something that isn't here."); ?></p>
<?php endif; ?>
<?php // End main loop to list page's static content ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment