I've created a page template and the goal is to create a loop that gets all posts by category name. The category name is passed from the slug of the page name. I haven't been able to get this to work entirely.
EDIT Here's my function for this loop (updated from answers):
global $post; $page_slug = $post->post_name; $category_query = new WP_Query(array( 'category_name' => $page_slug )); if ($category_query->have_posts()) : while ($category_query->have_posts()) : $category_query->the_post(); $output = '<h2 class="entry-title" itemprop="headline"><a href="'.get_the_permalink().'">'.get_the_title().'</a></h2>'; $output .= '<div class="entry-content" itemprop="text">'.get_the_content().'</div>'; endwhile; else : $output = '<h3>No posts found under "'.$page_slug.'"</h3>'; endif; wp_reset_postdata(); echo $output;
I screwed up somewhere, as all I get is a blank white page. Any suggestions on how to fix my loop to accomplish what I'm looking for?