WordPress.org

Support

Support » How-To and Troubleshooting » Showing and navigating posts by date/week… can it be done?

Showing and navigating posts by date/week… can it be done?

  • 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 15 replies - 1 through 15 (of 25 total)
  • Moderator keesiemeijer

    @keesiemeijer

    Are “Major News” ,”Update Author Post” and “Minor News” categories?

    oh, no, thats just what I was calling the posts. “Major news” would be the first post every week, itd be the main one that I would write, and it would be there every week.
    The other two are things that wont necessarily be there every week, such as if someone else wanted to post up a piece of news, or if I posted up a small update.

    If using some sort of categories would make things easier, and could be implemented easily enough for others to use too, then I’m happy to use them.
    I did wonder if making each “week” of posts a category would help… so if another author wanted to post up some news, theyd just have to make sure it was connected to the right category… I’m not sure if this is easy though, or if it would even work the way im thinking…

    Moderator keesiemeijer

    @keesiemeijer

    There are no WordPress pagination functions that do that, so we have to create our own. Try it with this in your theme’s functions.php: http://pastebin.com/gM5hBfKd

    Show the pagination functions in your index.php like this:

    <?php
    previous_week_link();
    next_week_link();
    ?>

    Or if you want to change the default labels “Previous Week”, “Next Week”:

    <?php
    previous_week_link('See previous week posts');
    next_week_link('See next week posts');
    ?>

    btw:
    consider creating a child theme instead of editing your theme directly – if you upgrade the theme all your modifications will be lost.

    ahh thank you, I will definately look into this, it seems promising! I plan on using a child theme file for all the customisations I do, for the very reason that I want to keep them all safe!

    Just reading through that file now, trying to get my head around it. ill let you know if t worrks, I’m sure others will find it useful too!

    thank-you again

    OK… I believe I did this correctly, but it does not seem to have worked (at least as far as I can see).

    I made a funtions.php in my child theme folder, and pasted that entire page from pastebin into it.
    I then pasted the index.php from the main theme into my child theme, and added those echo lines into it.

    but when I load up the front page, it just shows the most recent posts, with no pagination links.

    I’m guessing ive posted the lines in incorrectly, but im not sure where else they should go

    Oh… I do apologise, it turns out it does show up properly, the only reason it *wasnt* was because I didnt have any previous weeks for it to navigate to.

    As soon as I backdated a post to a month ago, a “previous” link appeared on the front page!

    So thankyou, it seems to be working as it should.

    Now I am going to need to find a way to have the “next” and “previous” links permenantly on the page, just greyed out if they dont link to anything.

    Moderator keesiemeijer

    @keesiemeijer

    If you change this:

    function next_week_link( $label = 'Next Week' ) {
    	echo get_week_link( $label, 'next' );
    }
    
    function previous_week_link( $label = 'Previous Week' ) {
    	echo get_week_link( $label, 'previous' );
    }

    To this:

    function next_week_link( $label = 'Next Week', $display = true ) {
    	if ( $display )
    		echo get_week_link( $label, 'next' );
    	else
    		return get_week_link( $label, 'next' );
    }
    
    function previous_week_link( $label = 'Previous Week', $display = true ) {
    	if ( $display )
    		echo get_week_link( $label, 'previous' );
    	else
    		return get_week_link( $label, 'previous' );
    }

    You can test if a link is returned. And if no link is returned echo the label:

    <?php
    $prev =  previous_week_link( 'Previous Week', false );
    $next =  next_week_link( 'Next Week', false );
    
    echo ( $prev != '' ) ? $prev : 'Previous Week'; // echo label if nothing is returned
    echo ( $next != '' ) ? $next : 'Next Week';
    ?>

    After a bit of a false start with this (for some reason, the first time i copied the code, a load of & symbols got included) I manage to get it all inserted properly, and it seems to be working wonderfully!

    Thankyou very much, all your help is really appreciated!

    Moderator keesiemeijer

    @keesiemeijer

    You’re welcome. I’m glad you got it resolved 🙂

    I’m not sure if you are still keeping track of this thread, but an unfortunate flaw has come up with this solution.

    I have been trying to exclude certain categories from my home page loop, as I dont want every type of new post appearing on my home page. In order to do this, I installed the this plugin.

    However, even if I only exclude one category from the home feed, the posts from previous weeks which are fine… do not appear. In fact, the message “Ready to publish your first post? Start Here” appears instead.

    I would say this might be a plugin issue, but the plugin doesnt seem to have issues like that. Besides, I did recently have to attempt to work around another problem which I think this navigation caused.

    This second problem was, that I wanted to change the order of posts on the homepage from descending to ascending (or ascending to descending… whichever is the opposite of default). However, whichever method I used to change the order, worked on the current weeks posts fine…. but when I clicked on the “previous week” button, the previous week would appear blank. No posts from that week would show.

    Im not sure where the conflict is appearing, I am hoping someone will be able to help me with a fix as I do really prefer the weekly navigation over the wordpress system.

    Thankyou.

    Moderator Andrew Nevins

    @anevins

    Forum moderator

    Bumps & duplicate threads will be deleted.

    Moderator keesiemeijer

    @keesiemeijer

    Try it with this in your theme’s functions.php: http://pastebin.com/P469Sid2
    And change the category ids you want to exclude in your home page (and home page rss):

    $my_exclude_categories = array( 1, 3 );
    $my_exclude_categories_rss = array( 1, 3 );

    Well once again you have come up with the fix I needed, thankyou so much!

    I assume I was meant to delete the original changes to my funtions.php and replace them with the one you just posted? Thats what I did and it seems to be working anyway.

    Will this new version also allow me to change the posting order on the front page? I would prefer them to be listed oldest -> newest for each week… though if this is a chore, I can simply change the publishing dates retroactivly so that it shows up in the order I want.

    Thankyou again anyway, at least I’m now able to exclude certain categories!

    Moderator keesiemeijer

    @keesiemeijer

    Try changing this:

    if ( is_home() ) {
                            $query->set( 'nopaging', true );
                            $query->set( 'category__not_in', $my_exclude_categories );
                            add_filter( 'posts_where', 'new_posts_where' );
                    }

    To this:

    if ( is_home() ) {
                            $query->set( 'nopaging', true );
                            $query->set( 'category__not_in', $my_exclude_categories );
                            $query->set( 'order ', 'ASC' );
                            add_filter( 'posts_where', 'new_posts_where' );
                    }

    didnt seem to make any difference… I tried changing ASC to DESC but btoh ways just formats the homepage to the default order of newest first.

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