This is a version of a function I’m using in the framework I’m working on, with example html replacing another function that contains something like it.
// Custom Loop
function arrr_custom_loop( $r_type="post", $r_post_num, $r_tax = 'category', $r_terms="featured" ) {
$args = array(
'showposts' => $r_post_num,
'tax_query' => array(
array(
'post_type' => $r_type,
'taxonomy' => $r_tax,
'field' => 'slug',
'terms' => array(
$r_terms
),
)
)
);
query_posts( $args );
if (have_posts())
while ( have_posts() ) : the_post();
$more = 0;
?>
<article>
<header class="pagetitle">
<?php if ( is_singular() ) { ?>
<h1><?php the_title(); ?></h1>
<?php } else { ?>
<h2 class="entry"><a href="https://wordpress.stackexchange.com/questions/23136/<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php } ?>
</header>
<div class="content_wrapper">
<div class="content">
<?php the_content(); ?>
</div>
</div>
<?php if ( comments_open() && ! post_password_required() ) { ?>
<div class="comments_wrapper">
<div class="comments">
<?php comments_template(); ?>
</div>
</div>
<?php } ?>
</article>
<?php endwhile;
wp_reset_query();
}
So you would then just use the function with the arguments created:
arrr_custom_loop( 'portfolio', 10, 'galleries', 'pirates' );