How about <?php if( is_category() && in_array( 'foo', get_the_tags() ) ) ) )?> where “foo” is the tag that you want to display?
http://codex.ww.wp.xz.cn/Function_Reference/get_the_tags
Thread Starter
Kahil
(@kahil)
I know that with php, I can use the syntax of || between to pieces to tell it to do one OR the other. I can’t seem to find one that signifies telling it to do this AND that.
You can use OR or || for “Or”..
You can also use AND or && for “And”..
|| and && are ever so slightly faster though, which is why they are more common.
Thread Starter
Kahil
(@kahil)
well… i thought that too, but couldn’t find a reputable online source that explicitly said that.
Here is what I have that isn’t working…
<?php if (is_category() && is_tag('30-sheets')); ?>
and for the following loop…
<?php rewind_posts(); ?>
<?php if (is_category() && is_tag('mall-kiosks')); ?>
for the particular category i am in, only one loop should show a post, the first one. right now it is showing the same post in both loops despite having different tags.
Test the conditions…
Example:
if( is_category() ) echo 'cat condition met';
else echo 'cat condition failed';
if( is_tag('30-sheets') ) echo 'tag condition met';
else echo 'tag condition failed';
Something totally obvious..
—
RE: The php operators..
http://www.php.net/manual/en/language.operators.logical.php
http://www.php.net/manual/en/language.operators.precedence.php
You need to have a parameter in is_category(), the cat id number or cat slug e.g
is_category('2')
or
is_category('cat-name')
EDIT: Sorry you don’t if it’s on the category page. Ref
Thread Starter
Kahil
(@kahil)
you don’t have to define a category. according to your reference, if you leave that empty it will go for any category archive.
The conditions will work, but only for one loop for some reason. despite declaring a specific tag in the first loop, it still shows the post with the other tag.
Thread Starter
Kahil
(@kahil)
here is what i have for my first loop…
<?php if (is_category() && is_tag('30-sheets')); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); $do_not_duplicate = $post->ID; ?>
and here is what i have for my second loop…
<?php rewind_posts(); ?>
<?php if (is_category() && is_tag('mall-kiosks')); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
Thread Starter
Kahil
(@kahil)
I figured it out on my own. If anyone is interested, here is a sample of the solution.
At the top of my template, before any loops, I have the following code to check to see what category the page I am on is and return its ID.
<?php foreach(get_the_category() as $category)
{ $thecat = $category->cat_ID; } ?>
Then, at the start of each loop I have the following. This code is set to call specific, constant post tags in respect to the particular category archive I am on.
<h2>30 Sheets</h2>
<?php query_posts('cat=' . $thecat . '&tag=30-sheets&order=ASC'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
---- THE CONTENT YOU WANT TO SHOW GOES HERE ----
<?php endwhile; ?>
<?php else : ?>
<div id="page">
<p class="center">There are no records for this media.</p>
</div>
<?php endif; ?>
<h2>Mall Kiosks</h2>
<?php query_posts('cat=' . $thecat . '&tag=mall-kiosks&order=ASC'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
---- THE CONTENT YOU WANT TO SHOW GOES HERE ----
<?php endwhile; ?>
<?php else : ?>
<div id="page">
<p class="center">There are no records for this media.</p>
</div>
<?php endif; ?>
You can do this for as many loops and tags as you like.