Forums

Query posts by category OR page (5 posts)

  1. soyuz
    Member
    Posted 4 years ago #

    hi there,

    i have a website using wordpress. on the front page i have a banner slideshow of the small screenshots from the portfolio category (in my case, cat=9). the banner is from the custom field of each portfolio posts and have links to the specific post.

    here is the code:

    <?php query_posts('cat=9');
    	$slide = 1;
    	while (have_posts()) : the_post();
    	if (post_custom('preview')) { ?>
    	<div id="slideshow<?php echo $slide;?>"<?php if ($slide != 1) { ?> style="display: none;"<?php } ?>>
    	<a href="<?php the_permalink();?>">
    	<img src="<?php echo post_custom('preview');?>" alt="<?php the_title();?>" class="previewpic" />
    	<span><?php the_title();?></span>
    	</a>
    	</div>
    	<?php $slide++;} endwhile; ?>

    what i want to do now is add the query post so that the banner will shows not only from cat=9 but also from page_id=2 (this is the about us page).

    i try to put like this:

    <?php query_posts('cat=9&page_id=2');
    
    ..and so on..

    but it doesn't work, only shows the banner from the page_id=2.

    I would be tremendously obliged if you help me and tell me how to get this done.

    thanks.

  2. nudnik
    Member
    Posted 4 years ago #

    I'm not totally following, but it looks like you want it to be OR page_id=2, not AND page_id=2.

  3. Kafkaesqui
    Moderator
    Posted 4 years ago #

    First, Pages cannot be assigned to a category. So even it your query were to work, it couldn't. Second, 'cat' and 'page_id' are two very different types of queries which cannot be used to complement or modify the other. So you can have 'cat=9' or 'page_id=2', but not both.

    In any case, based on what you describe it looks more like you're in need of the is_page() conditional to decide when to display this banner. See:

    http://codex.wordpress.org/Conditional_Tags#A_PAGE_Page

  4. soyuz
    Member
    Posted 4 years ago #

    i see. that's why it's only showing the Pages' banner *sigh*

    thanks for the tips, i will look into it.

  5. burtonkent
    Member
    Posted 3 years ago #

    Actually, if you want to have the main loop work, and also have subqueries, you're going to have to use wp_query instead of query_posts. See: http://codex.wordpress.org/Template_Tags/query_posts for details.

Topic Closed

This topic has been closed to new replies.

About this Topic