• I am trying to have a custom page or template appear when querying more than one category.

    After the header, I have:

    <?php if (have_posts()) : ?>
    <?php /* If this is a category archive */ if (is_category('harlequin') || ('2007')) { ?>
    <?php } ?>

    This is intended to show all the posts that have the categories Harlequin & 2007. I made it a page template and then created a page called Harlequin 2007. No posts show up.

    Link Here:

Viewing 12 replies - 1 through 12 (of 12 total)
  • Use:

    (is_category(‘harlequin’) || is_category(‘2007’)) {

    Thread Starter JaneLitte

    (@janelitte)

    I tried that but no success. Can I use IDs instead of the name?

    ID’s are better imo.

    Thread Starter JaneLitte

    (@janelitte)

    I changed to (is_category('26') || is_category('16')) {
    and it still did not work. Should I be tackling this from a different angle?

    I made it a page template and ..

    thats your trouble.

    pages and posts dont go together.

    ‘pages’ in wordpress arent for displaying posts.

    Thread Starter JaneLitte

    (@janelitte)

    How would I have the particular template be called for then? Would I just have category.php and include a number of conditional queries such as the following?

    <?php
    if (is_category(16)&&is_category(26)) {
       // looking for category 16 & 26 posts
       include(TEMPLATEPATH . '/combined.php');
    } else {
       // put this on every other category post
       include(TEMPLATEPATH . '/archive.php');
    }
    ?>

    yes, that looks like it might work. ?? it’s got a better chance than what you were doing ??

    Thread Starter JaneLitte

    (@janelitte)

    If I put the above code in a category.php file, does there need to be anything else but the query or do I put the query in the index.php page?

    Because that is what I did and it doesn’t “select” the special php file (which I named combined.php).

    This is the url I used.

    https://romanticadvances.com/?s=&cat=26&cat=16

    Hello Jane,

    I think you can get posts that fall in more than 1 category by using the UTW plugin. Please read https://www.ads-software.com/support/topic/101587?replies=3

    -PD-

    Hello Jane,

    Found a plugin that might solve your problem.

    This plugin allows to use categories as intersections. Normally when multiple categories are chosen, they will be ORed (a union), but with this plugin they will be ANDed (an intersection). So if category x and y are chosen, it will not show posts from cat x and cat y, but only those that belong to both categories. (example ?cat=1,2&intersect=1)

    Download URL: https://www.tester.ca/files/intersect.php.txt

    -PD-

    Thread Starter JaneLitte

    (@janelitte)

    Okay, so I installed the plugin and added the following if statement to the category page:

    <?php /* If this is a category archive */ if (is_category('26')) {
    	   include(TEMPLATEPATH . '/harlequin.php');
    } elseif (is_category(18)&&is_category(26)) {
       include(TEMPLATEPATH . '/combined.php');

    and used this url

    https://romanticadvances.com/?cat=26,18&intersect=1

    and it pulls up harlequin.php instead of combined.php and there is an error message at the top.

    WordPress database error: [Unknown table 'wp_post2cat' in where clause]
    SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts LEFT JOIN wp_post2cat AS p2c0 ON (wp_posts.ID = p2c0.post_id) LEFT JOIN wp_post2cat AS p2c1 ON (wp_posts.ID = p2c1.post_id) WHERE 1=1 AND wp_post2cat.category_id IN (26, 27, 32, 33, 34, 35, 36, 37, 68, 85, 96, 18) AND (post_type = 'post' AND (post_status = 'publish' OR post_status = 'private')) GROUP BY wp_posts.ID ORDER BY post_title ASC LIMIT 0, 10

    I think at this time, I might give up. I can do the tag unions using UTW but I can’t figure out how to get the unique php files to come up.

    Is it as simple as
    if (is_utwtag('harlequin') && is_utwtag('july')) {

    because i know that in the url for the tag union, you use a + sign, but the php conditional for an intersection is &&

    Thanks so much for all your help. I know that this is a volunteer forum and I really appreciate the time you all have spent looking at this issue and directing me to the right places, even if I can’t quite figure it out. ??

    Hi Jane,

    I have not used the intersect plugin myself. I hope to try it in the next blog I do.

    -PD-

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Condition is_category help needed’ is closed to new replies.