• Resolved Mooshon

    (@mooshon)


    Hi. Really hope someone can help with this as I’ve been chasing my tail for days. Also not being fluent in php isn’t helping matters.

    I’m developing a computer game news/reviews site, (dlcentral.co.uk) where it is often required that a post is assigned to multiple categories (Xbox, PS3, Wii U etc). I have created custom category templates and css to colourise each section accordingly. The problem I am facing is the current logic that WP uses regarding multiple categories – where all permalinks are redirected to the child category with the lowest ID. It is really important that the permalinks on my query_posts stay within the parent category.

    I have tried loads of various fixes. Excluding/including child categories in a query just adds/removes unwanted categories, and all other is / in_category is just being ignored. However, I stumbled up this snippet which gets me almost there:

    <?php
    $cat_object = $wp_query->get_queried_object();
    $parentcat = ($cat_object->category_parent) ? $cat_object->category_parent : $cat;
    wp_list_cats("child_of=$parentcat");
    ?>

    This code returns the ‘true’ list of the active/parent category child categories without the (non active, attached) descendant categories. Question is, is it possible to roll this code into my standard query_post call:?

    <?php query_posts('category_name=xbox360&showposts=1&offset=6'); ?>
    			<?php while (have_posts()) : the_post(); ?>
                <?php get_template_part( 'content', 'portfolio' ); ?>
                <?php $do_not_duplicate = $post->ID; ?>
                <?php endwhile; ?>

    …I’m hoping this will have the desired effect of returning only active category posts/links rather than the child category posts of everything.

    Sorry about the wall of text. Help please!!

Viewing 1 replies (of 1 total)
  • Thread Starter Mooshon

    (@mooshon)

    May as well post my outcome. No help forthcoming and there appears to be absolutely no standard solution to posts within multiple categories acting correctly in wordpress.

    To any weary traveller hitting this dead end – The only fudge workaround is to use: HTTP_REFERER. This code can detect which category you have come ‘from’ allowing you display a custom template, rather than WP just making your parent category the descendant parent with the lowest id. Combined with the technique to use custom single.php files for categories (and bespoke css to colourise your sections) you can consistently colourise your Post template page to match the section that you’re in:

    <?php
    if(strstr($_SERVER['HTTP_REFERER'],'xbox360')) {
    	include 'single-xbox360.php';
    } elseif (strstr($_SERVER['HTTP_REFERER'],'ps3')) {
    	include 'single-ps3.php';
    } else {
    	include 'single-plain.php';
    }
    ?>

    Nothing else works. Until WP changes the way it works there is no other solution regarding multiple category posts. Considering trawling through these here forums for the last week just uncovered tonnes of desperate people struggling with this for the last 5 years plus that’s pretty unlikely to happen.

Viewing 1 replies (of 1 total)
  • The topic ‘Multiple child categories assigned to Post bug/issue’ is closed to new replies.