Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have built a specific page to display only the posts in specific children categories. I want to have the monthly archive on the right hand side but only relating to those specific children categories.

So far I have this, however it is ignoring the child_of and displaying everything.

<?php $arc = array(
'type'            => 'monthly',
'limit'           => '',
'format'          => 'html', 
'before'          => '',
'after'           => '',
'show_post_count' => false,
'echo'            => 1,
'order'           => 'DESC',
'child_of' => 19);?>
<?php wp_get_archives( $arc ); ?> 

And here is my page of code.

<div class="container">
<div class="row">
    <div class="col-lg-7 col-md-7 col-sm-8">
        <h1 class="entry-title-big">Knowledge</h1>
        <?php
            $catquery = new WP_Query( 'category_name=knowledge' );
            while($catquery->have_posts()) : $catquery->the_post();
        ?>
            <article class="articlePost clearfix">
                <?php if ( has_post_thumbnail() && ! post_password_required() && !is_single() ) : ?>
                <div class="entry-thumbnail col-lg-5 col-md-5 col-sm-5">
                    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
                        <?php the_post_thumbnail('full', array('class' => 'img-responsive'));   ?>
                    </a>
                </div>
                <?php endif; ?>
                <div class="clearfix postDets">
                    <div class="the-date"><?php the_time('F j, Y'); ?></div>
                    <div class="the-categories">
                        <?php                           
                            $categories = get_the_category();
                            $separator = ' ';
                            $output = '';
                            if($categories){
                            foreach($categories as $category) {
                            $output .= '<a class="feedcat" href="'.get_category_link( $category->term_id ).'" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '">'.$category->cat_name.'</a>'.$separator;
                            }
                            echo trim($output, $separator);
                            }
                        ?>
                    </div>
                </div>

                <a href="<?php the_permalink() ?>" rel="bookmark" class="entry-title"><?php the_title(); ?></a>
                <?php the_excerpt(); ?>
                <a class="read-more" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
                    Read More...
                </a>
            </article>
        <?php endwhile; ?>

        <?php wp_reset_query(); ?> 
    </div>

    <aside id="serSideBar" class="col-lg-4 col-lg-offset-1 col-md-4 col-md-offset-1 col-sm-4">
        <div id="catsWidget">
            <h2>Categories</h2>
            <ul>
                <?php

                $args = array(
                  'orderby' => 'name',
                  'order' => 'ASC',
                  'child_of' => 19
                  );
                $categories = get_categories($args);
                  foreach($categories as $category) { 
                    echo '<li class="cat-item"><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a>';
                    echo '('. $category->count . ')</li>';  } 
                ?>
            </ul>
        </div>
        <div id="arcWidget">
            <?php $arc = array(
                'type'            => 'monthly',
                'limit'           => '',
                'format'          => 'html', 
                'before'          => '',
                'after'           => '',
                'show_post_count' => false,
                'echo'            => 1,
                'order'           => 'DESC',
                'child_of' => 19
            ); ?>           
            <?php wp_get_archives( $arc ); ?> 
        </div>
    </aside>
</div>

share|improve this question
    
Please post all of the relevant code! –  s_ha_dum May 2 at 15:01
    
I have updated the code, which now shows how I am pulling in all of the information. –  user2648610 May 2 at 15:53

1 Answer 1

There is no child_of argument for wp_get_archives(). How, or why, did you expect that to work? You are attempting to use arguments that don't exist. That, I suppose, is the answer to the question. The function is ignoring child_of because the argument doesn't exist.

There are a number of filters in wp_get_archives() such as getarchives_where and getarchives_join that you should be able to use to achieve what you want, but the SQL is going to be complex.

But before running down that rabbit hole, what is the relationship to "wordpress's monthly archive widget"? Are you hacking Core? If so, the correct solution to this problem is most likely "create your own widget" and necessary code will be quite different.

share|improve this answer
    
Sorry thats because I took it from get_categories and was testing to see if it would work. I have had to build a specific page to display only posts from a collection of children categories. So I then I went the archive to work only for those categories also. –  user2648610 May 2 at 14:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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