• Resolved sachinrocks

    (@sachinrocks)


    Hello,

    How to display current week post in each category.

    Eg: cat1 current week post should diplay in cat1 only
    cat2 current week post should diplay in cat2 only.

    Currently i am usin this code, but its displaying all category poat in each category

    <?php
                         $week = date('W');
                         $year = date('Y');
                         query_posts('cat=&post_type=post&posts_per_page=10&orderby=comment_count&order=DESC&year=' . $year . '&w=' . $week);
                         while (have_posts()): the_post(); ?>
    
                        <a>"><?php the_title(); ?></a>
    
                              <p><?php content('40'); ?></p>
                         <?php endwhile; wp_reset_query(); ?>

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    Please Help
    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • @sachinrocks Do you want to give this code a go?

    <?php $args = array(
    	'post_type' => 'post',
    	'posts_per_page' => 10,
    	'order' => 'DESC',
    	'orderby' => 'comment_count',
    	'cat' => 1,
    	'date_query' => array(
    		array(
    			'year' => date('Y'),
    			'week' => date('W'),
    		),
    	),
    );
    $query = new WP_Query( $args );
    
    if ( $query->have_posts() ) :
    	while ($query->have_posts()): $query->the_post();
    ?>
    		<a>"><?php the_title(); ?></a>
    		<p><?php content('40'); ?></p>
    <?php
    	endwhile;
    endif;
    wp_reset_postdata();
    ?>
    Thread Starter sachinrocks

    (@sachinrocks)

    Hello,

    Thanks for the reply.

    I have tried this code but its not working as per my wish.

    I need to display only current week post in respected categories.

    The above code (my code) displaying current week post but its displaying same post on each category. But i need to display post only on assigned category.

    Thanks.

    Just to clarify, are you struggling with category or date filtering?

    You can filter by category name or id no problem – please see docs here.

    Thread Starter sachinrocks

    (@sachinrocks)

    Hello,

    I just need to display current week post in its own category,

    Its an magazine site, so i need to show current week post on its category. There are more than 10 category. so i need to display current week post in categories.

    Eg: cat-1’s current week post should display in cat-1 only
    Cat-2’s current week post should display in cat-2 only.

    Sorry If I am still not clear.

    Thread Starter sachinrocks

    (@sachinrocks)

    Hello,

    Its resolved thanks for the help.

    Here is the code

    <?php
    $category = get_the_category();
    $week = date('W');
    query_posts('w=' . $week.'&cat='.$category[0]->term_id); ?>
    <?php while (have_posts()): the_post(); ?>
    <a href="<?php the_permalink(); ?>">
    <?php the_title(); ?></a>
    <?php content('40'); ?>
    <?php endwhile; ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to display current week post in category’ is closed to new replies.