0

Part of the website I'm working on is meant to function like a monthly magazine, with a few different departments. So I have 'Magazine' set as the parent category, and say 'Art' and 'Music' as child categories (which may have further subcategories).

THE GOAL
I'm trying to set up a permalink structure so that, for example, http://mysite.com/magazine/2014/12 will show a page that contains all the posts from 'Magazine' and its subcategories for December, 2014.

THE CURRENT STATE
Currently, my permalink structure is set to: /%category%/%year%/%monthnum%/%day%/%postname%/

Going to the URL above effectively results in visiting http://mysite.com/magazine/—the posts are from multiple months. However, visiting http://mysite.com/art/2014/12 works, in that I see all 'Art' posts for the specified month.

Do I need a complex rewrite, or am going about this the wrong way? I came across this, which is basically the opposite of what I want to do: Remove parent category from permalink? Basically only have the child category?.

Any insights would be greatly appreciated.

Thanks.

UPDATE 1
I decided to temporarily remove my custom category template category-magazine.php and the magazine archive works correctly. So something with my template is breaking it. It's split into three loops (one for each department). Is that causing the problem perhaps???

UPDATE 2
So here is what I have in my multi-loop category-magazine archive:

    <?php // 1st Query
    $col1 = new WP_Query(
        array(
            'posts_per_page'            => 1,
            'cat'                       => 31
                )
            );
    ?>

    <?php if ( $col1->have_posts() ) : ?>

        <div class="post-list group col-1">

            <?php while ( $col1->have_posts() ): $col1->the_post(); ?>
            <?php get_template_part('content'); ?>
            <?php endwhile; wp_reset_postdata(); ?>

        </div><!--/.post-list-->


        <?php endif; ?>

        <?php /* The 2nd Query  */
        $col2 = new WP_Query(
            array(
                'posts_per_page'            => 1,
                'cat'                       => 28
            )
        );

        ?>

        <?php if ( $col2->have_posts() ) : ?>

            <div class="post-list group col-2">

            <?php while ( $col2->have_posts() ): $col2->the_post(); $col2->next_post(); ?>
            <?php echo get_template_part('content'); ?>
            <?php endwhile; wp_reset_postdata(); ?>


            </div><!--/.post-list-->

    <?php endif; ?> `

This works fine when visiting the magazine category page, but it doesn't work for archive pages.

0

Alright, I solved it:

I queried the year and month of the page we're on with:

$year     = get_query_var('year');
$monthnum = get_query_var('monthnum');

And then I added date parameters to each WP_Query:

        $col1 = new WP_Query(
        array(
            'year'                      => $year,
            'monthnum'                  => $monthnum,
            'posts_per_page'            => 1,
            'cat'                       => 31
            )
        );

This allows me to split the departments of the 'Magazine' archive page into different areas, rather than have them mixed in one loop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.