wordpress customize categories in the loop query

Discussion in 'WordPress' started by inklight, Oct 31, 2010.

  1. #1
    Hi
    I design wordpress theme that view one post from 4 specialized categories in the main page ..
    here is code for the loop in index.php

    <?php if (have_posts()) : query_posts('category_name=protection','category_name=internet'); 
     while (have_posts()) : the_post(); ?>
    <div id="post-<?php the_ID(); ?>"  <?php post_class('post_All . $Post_Calss'); ?>   
    	<h2><?php echo $Cat_Name;?></h2>
    	 <h4 id="post_H2"  class="entry-title">
    	 <a href="<?php the_permalink() ?>" rel="bookmark" title="Download<?php the_title_attribute(); ?>">
         <?php the_title(); ?></a></h4>
    	<div class="entry"  > 
    <?php the_content('<div class=more1>Read More ..</div>'); ?>  
    <p class="postmetadata"><?php edit_post_link('Edit', '', ''); ?>  </p>
    </div>
    	</div>
    		<?php endwhile; ?>
    ......the rest of index codes 
    PHP:
    but the loop view only posts from one categories
    I know the problem are in the query its take the firs query only .
    until now i cant figure out how to make the query work with multi values that i wont ..
    same thing with the $Cat_Name operand th I want it to have current categories name value .
     
    inklight, Oct 31, 2010 IP
  2. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Do you have to use category names? query_posts accepts multiple category IDs but not names.

    If you need to use names, try the method given in this post.
     
    Cash Nebula, Nov 1, 2010 IP
  3. inklight

    inklight Member

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    38
    #3
    ^^ thanks Cash Nebula
    I was thinking in similar solution and it's work for me now
    $catIDs =get_cat_ID($cat_name='protection');
    $catIDs .=','.get_cat_ID($cat_name='internet');
    $catIDs .=','.get_cat_ID($cat_name='graphics');
    query_posts("cat=$catIDs&showposts=1");
    PHP:
    And I Working working on other tweaking that shows one post from specialized categories(that I done with it) and order thats post by categories name in the main page ..
    I mean post in categories protection will shown first , second the post in categories internet , then the post in categories graphics
    this is diagram for contents page
    [​IMG]
     
    inklight, Nov 2, 2010 IP