Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

starapple on "Alternative to query_posts to get categorie and posts info"

$
0
0

Hi and a great day to you.

I've been using with the desired results, query_posts() in the home page of a theme I've been writing, to return specific categories and their posts with titles, permalinks and the attached image. But reading the Codex it advises and warns against using query_posts in themes and plugins. Is there an alternative suitable way (query) to get the info I want? Would it be better to place it in functions.php?

This is what I have:
`$display_categories = array(36,32,21,14,10);
foreach ($display_categories as $category) {
query_posts("showposts=4&cat=$category");
$wp_query->is_category = false;
$wp_query->is_archive = false;
$wp_query->is_home = true;
$category_link = get_category_link( $category );?>`

and
`<h3 class="text_line"><a href="<?php echo $category_link;?>">
<?php // name of each category gets printed
wp_list_categories('include='.$category.'&title_li=&style=none');?>
</a></h3>
<div class="scroller">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>`

to return the_permalink(), the_title_attribute()

Your help will be greatly appreciated.

Msrk.


Viewing all articles
Browse latest Browse all 8245

Trending Articles