• I am attempting to design a blog section for my site, and the design I would *like* to have is causing me some issues…

    This is what I want it to end up being:

    My homepage will show the current weeks blog entries. The first “main” one will be the weekly update information, and will always be the first one on a week.
    Below that, posted at various times during the week, will be the occasional more “minor” updates, posted by me or by other authors.
    So the home page will have, for example, the Major News post, an Update Post from another author, and a Minor News post from later in the week.

    This is where it seems to get more complicated. Once the week has passed, and it is time for a new Major News post, I want all three of those previous posts to stay together, but go to a previous page.

    For example:
    Home page = week beginning 10th march – Major News, Author Update, Minor News
    Then, if you press “back” (or “previous”) on a navigation button:
    Archive page = Week beginning 3rd MArch – Major News, Minor News
    Press “previous” again and the page should show all the posts for:
    Week beginning 26th Feb – Major news, Author Update, Author Update

    …. and so on, and so forth.

    The problem I’m having when searching for this solution, is that the custom navigation plugins seem to only allow for showing a single post at a time… I want to be able to navigate back and forth between pages of several posts, but to only show posts from a specific time frame.

    Is this actually possible? I’m hoping I have simply been searching the forums using the incorrect terminology…

    Thankyou to anyone who can help me!

Viewing 10 replies - 16 through 25 (of 25 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Try removing the space in 'order '

    $query->set( 'order', 'ASC' );

    Thread Starter nirurin

    (@nirurin)

    Haha, typical, I hadnt even noticed there was an extra space. Thanks again, you sir are a legend.

    Moderator keesiemeijer

    (@keesiemeijer)

    You’re welcome.

    This post was exactly what I needed… thanks keesiemeijer!

    Also (to sidetrack a bit), I understand that this custom functions are to be used with the standard WordPress Loop. I tried WP_Query, but it isn’t displaying anything.

    Is there a difference between the standard Loop and a WP_Query Loop?

    Moderator keesiemeijer

    (@keesiemeijer)

    Is there a difference between the standard Loop and a WP_Query Loop?
    Yes, WP_Query is usually used for secondary loops.
    see:
    https://wordpress.stackexchange.com/questions/50761/when-to-use-wp-query-query-posts-and-pre-get-posts
    https://www.billerickson.net/customize-the-wordpress-query/
    https://developer.wordpress.com/2012/05/14/querying-posts-without-query_posts/

    The functions use the pre_get_posts hook to query the loop.

    You could try using WP_Query like this [untested].

    global $my_exclude_categories;
    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    $args =  array(
    'category__not_in' => $my_exclude_categories,
    'paged' => $paged,
    );
    add_filter( 'posts_where', 'new_posts_where' );
    $query = new WP_Query( $args );
    remove_filter( 'posts_where', 'new_posts_where' );
    // loop goes here

    And remove this line:

    add_action( 'pre_get_posts', 'weekly_pagination' );

    Awesome information!

    I’m trying out the WP_Query you’re providing, but it doesn’t seem it work. Right now I’m tweaking the code to see if I can achieve anything with it, but while I’m actually trying to contain the weekly pagination to a single WP_Query itself, I have another WP_Query that displays ‘featured’ content on the same page.

    Pagination is giving me a problem as well, every time I go to /page/2, both content queries go to the next page. I just want one to change. Is it even possible?

    EDIT: I actually found a question on SE that answered whether its possible, I’m giving it a try now to see if it works.

    Link’s here : https://wordpress.stackexchange.com/questions/47259/multiple-wp-query-loops-with-pagination

    Right, right now I understand that because of this function,

    add_action( 'pre_get_posts', 'weekly_pagination' );
    function weekly_pagination( $query ) {
    	if ( !is_admin() && $query->is_main_query() ) {
    		if ( is_home() ) {
    			$query->set( 'nopaging', true );
    			add_filter( 'posts_where', 'new_posts_where' );
    		}
    	}
    }

    this actually modifies the entire loop for the index.php page. However, is there a way to limit if( is_home() ) to just a selected loop? Because right now I have 2 queries on my homepage, and this is changing the secondary loop (I’m using the original Loop for the weekly posts) into a weekly one as well.

    Moderator keesiemeijer

    (@keesiemeijer)

    I’ve tested it and this seems to work:

    <?php
    global $my_exclude_categories;
    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    $args =  array(
    'category__not_in' => $my_exclude_categories,
    'nopaging' => true
    );
    add_filter( 'posts_where', 'new_posts_where' );
    $query = new WP_Query( $args );
    remove_filter( 'posts_where', 'new_posts_where' );
    ?>

    Can you post the full code with both loops.

    Your new loop works perfectly! With that fixed, my first loop is working normally now.

    All I need right now is for the first loop to display the pagination separately from the second loop.

    Here’s the code with both loops, as you requested (if you want a reference).

    <div id="body" class="full-block">
        	<div id="main-content">
    			<?php $featured_query = new WP_Query(array( 'category_name' => 'featured', 'posts_per_page' => 3, 'paged' => ( get_query_var( 'paged' ) ))); while( $featured_query->have_posts() ): $featured_query->the_post(); ?>
                	<img class="featured-image" src="" />
                    <span class="featured-title"><?php the_title(); ?></span>
    			<?php endwhile; ?>
                <?php wp_reset_postdata(); ?>
            </div>
            <br /><br /><br />
            <div id="sub-content">
                <?php
    		global $my_exclude_categories;
    		$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    		$args =  array(
    		'category__not_in' => $my_exclude_categories,
    		'nopaging' => true
    		);
    		add_filter( 'posts_where', 'new_posts_where' );
    		$query = new WP_Query( $args );
    		remove_filter( 'posts_where', 'new_posts_where' );
    	    ?>
                <?php while( $featured_query->have_posts() ): $featured_query->the_post(); ?>
                	<h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permalink to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                    <p><?php the_content(); ?></p>
                <?php endwhile; ?>
                <?php wp_reset_postdata(); ?>
                <?php previous_week_link() . next_week_link(); ?>
            </div>
        </div>

    I can’t thank you enough for helping me with this.

    Not sure if I should piggyback on this or move to a new thread but I’m trying to get similar functionality worked out but instead of weekly it would be daily. The navigation being next day, previous day, and so on.

    I’ve been searching for daily pagination for a few days and have come up short. I can get the pagination part to work – displaying links and such – but then it doesn’t query for posts from that day. Just using a simple loop to run it:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $today = getdate();
    query_posts("year=$today[year]&monthnum=$today[mon]&day=$today[mday]&paged=$paged&orderby=date&order=asc");
    if (have_posts()) :
       while (have_posts()) : the_post();
    ?>

    It’s a little daily events calendar type thing.

    Let me know if I need to move this to a new thread too…

Viewing 10 replies - 16 through 25 (of 25 total)
  • The topic ‘Showing and navigating posts by date/week… can it be done?’ is closed to new replies.