Can I automate a loop query based on category with the page's title?
Posted
by
jordaninternets
on Stack Overflow
See other posts from Stack Overflow
or by jordaninternets
Published on 2011-03-11T08:06:31Z
Indexed on
2011/03/11
8:10 UTC
Read the original article
Hit count: 166
Wordpress
|wordpress-loop
To explain further, I need to get a page to display posts from a specific category. I want to automate this process so I don't have to make a template for each category. How would I do that? (keep in mind the person I'm building this is for has no coding experience.)
The only way I could think off from the top of my head is to use the title or slug. So if the category is named the same thing as the slug, could I filter by category using the slug? Maybe this isn't the best way... what should I do?
This is what I came up with, but it doesn't work, I'm sure due to improper use on may part, but I've been pouring over the WP codex and Google with no avail to tell me my problem.
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args= array(
'orderby' => 'date',
'order' => 'ASC',
'paged' => $paged,
'category_name' => echo the_title('\'','\'',)
);
query_posts($args);
?>
© Stack Overflow or respective owner