ThemeShaper Forums » Thematic


Two Index Loops? Maybe?

(18 posts)
  • Started 11 years ago by vicky515
  • Latest reply from vicky515
  • This topic is not resolved
  1. vicky515

    This is probably really simple, and I tried asking in the Wordpress forums, but in over two weeks I've got no help.

    I have the Thematic Index loop which shows the most current post in it's entirety on the homepage (among other things). What I'd like to have is a menu item called "Blog", which will show the most recent 10 or so posts.

    Now I'm confused about how to accomplish this. It doesn't look like there's anyway to do so in Wordpress' admin UI. If I change Settings > Reading to use a static page, then it's just using my Index loop for loop (which only shows the most recent post). Even if I change the number of posts to 10, my Index Loop is hard-coded to only show 1, so it's only showing 1 under the "Blog" item. Obviously.

    Now, creating a second loop isn't a problem (I don't think - I'm assuming I can easily copy and paste the relevant code with different names), but I have no idea where to start. Literally. page.php, category.php, none of the existing files seem appropriate. Do I create a new file from scratch like blog.php? Will it inherit Wordpress' functionality - Like pagnation?
    It's probably really obvious but I've been stuck on it for awhile. And no luck searching either - perhaps I'm using the wrong terminology?

    Thank you so much for your help.

    Posted 11 years ago #
  2. I usually insert extra loops with a conditional tag like is_front_page() and hook them the area I want (you can refer to )

    Quick example:

    function extra_loop() {if (is_front_page()) { 
    // your loop here
    add_action('thematic_abovecontent', 'extra_loop');

    If I understand what you want to do correctly you might want to look into this too:

    Posted 11 years ago #
  3. vicky515

    Hey Joperron - thanks for responding. But it seems like I haven't explained myself very well...

    This is difficult for me to explain... Please bare with me :)
    I have no idea what condition I would use just for the Blog. So let's say I change my index loop to the blog loop (show all posts), and create a new loop with this "if is_front_page" condition (only show the most recent post, as my current Index loop does).
    That's fine, I follow up until this point.

    But then what would I be linking that "Blog" link to in my navigation so that it picks up my custom loop?

    I hope that makes sense - thanks so much for your help.

    Posted 11 years ago #
  4. vicky515

    Ok, so here's my modified Index loop... I've created a "blog" page in Wordpress to experiment with...

    function mod_index_query() {
    global $wp_query;
    	if (is_front_page()) {
    		$defaults = $wp_query->query_vars;
    		$custom = array('posts_per_page'=> '1');
    		$args = wp_parse_args( $custom, $defaults );
    	} else {
    		$defaults = $wp_query->query_vars;
    		$custom = array('posts_per_page'=> '10');
    		$args = wp_parse_args( $custom, $defaults );

    Under "Reading", the following "front page displays" settings cause the following set-ups.
    1. Your latest posts: Homepage shows mose recent post (expected), Blog shows blog page with no posts.
    2. A static page, Front page nothing, most recent posts nothing: Homepage shows most recent post (expected), Blog shows blog page with no posts.
    3. A static page, Front page "Blog", most recent posts nothing: Homepage shows Blog page which has no posts, Blog shows blog page with no posts nothing.
    4. A static page, Front page nothing, most recent posts "Blog": Homepage shows 10 most recent posts (Blog should show this), Blog shows 10 most recent posts (expected)
    5. A static page, Front page "Blog", most recent posts "Blog": Homepage shows Blog page with no posts, Blog shows blog page with no posts.

    I'm not sure if I'm on the right track or not, but it seems like configuration #4 is the most promising... But I'm not sure which is_home_page isn't working...

    Any input would be appreciated.

    Posted 11 years ago #
  5. vicky515

    I feel like I'm going about this all wrong :(

    Posted 11 years ago #
  6. hi vicky515,
    Create a template "home" for your home page that shows just one post so when you select it as a static page it will know what to do.

    Posted 11 years ago #
  7. vicky515

    Hi Lastraw, can you elaborate?
    So I copy page.php as page-home.php? Do I understand? And how do I get it to show just one post? Another custom loop? :\

    Posted 11 years ago #
  8. vicky515

    Bump. I've been stuck on this for over a month now and would like to get it resolved.

    Posted 11 years ago #
  9. "my Index Loop is hard-coded to only show 1"


    I probably would have just copied the thematic blog template into my child's folder, renamed it, renamed the header/file info (the stuff in comments) so that it would be recognized as something different.

    then change the query args right there to only show 1 post.

    now on the page you want to show 10 posts, select the thematic blog template. on the page you want to show only 1 post. select your new template.

    don't take this the wrong way but if you've spent a whole month stuck on something wouldn't it have been better to pay someone to solve that issue? I'm not fishing for work, but it just seems like your time has to be worth the $50 it might have taken someone to do this for you.

    hope my suggestion helps. it strikes me that you've overcomplicated things.

    Posted 11 years ago #
  10. vicky515

    Funny you should say that, because I was considering adding that to my bump post out of desperation. But rather I was willing to pay for someone to help me, not do it for me. I'm here to learn, afterall. I don't like being a pest, but aside from forums (which I did a few weeks prior to posting here), there's literally no where else I can go for help.
    I didn't put it because of the first sentence of my first post "This is probably really simple..." I was honestly expecting someone to go "oh man, its so much easier than that" and write a few sentences. Then I'd go "yeah i'm retarded! thank you! i love you with mouth!" And move on.

    Oh well :(

    Thank you so much for responding. That sounds a lot better... I will try it and update!

    Posted 11 years ago #
  11. understood and i defo like it when people are here to learn. but sometimes you can learn a lot from seeing the answer. did my suggestion work out for you?

    there are other places you can go for help:

    Posted 11 years ago #
  12. vicky515

    It did! And just as I was about to jump for joy, I tried pagnation and got a 404... Works on the homepage though. Blog page is giving me 404 everytime. Last time I had an issue with pagnation it was because I had "." in my root category. Now it's set to "blog", so that isn't the issue...

    I've gone over it a few times, my changes were:

    1. Comment out my index loop in functions.php

    2. Add the code below in index.php after <div id="content">

    			$wp_query = new WP_Query();
    			$wp_query->query( array( 'posts_per_page' => '1', 'paged' => $paged ) );
    			$more = 0;

    3. Copy & paste template-page-blog.php from Thematic parent class to my child theme, rename to page-blog.php, and replace get_option( 'posts_per_page' ) with '2' for testing

    Any idea?

    Posted 11 years ago #
  13. try re-saving your permalinks. that sometimes solves weird 404 issues. next, we might have to figure out whether $paged is getting any kind of value.

    Posted 11 years ago #
  14. vicky515

    no luck :(
    I tried print_r($paged); and the value printed was 0. So I'm guessing it's a boolean returning false?

    Posted 11 years ago #
  15. which page is failing? and just b/c i am confused, you want the front page to serve only the latest post while a "blog" page serves the latest 10? that sounds like you only need to make something custom for that page that shows the 1 post as the other action is default. which makes me think you should leave index.php and your index loop alone. i dont think you need to mod that when it actually produces one of the behavior you are after. if you create the new 1 post template i described before, you can assign that page template to any page and then set that page as your front page in the WP "reading settings". you can also assign any other page to be your blog page and show the latest 10 posts.

    Posted 11 years ago #
  16. vicky515

    Sorry Helga, I'm really confused about what you're suggesting, if you don't mind clarifying? I just wiped out everything I've done from my last post and I'm going from scratch.

    You are correct in that the homepage only shows the most recent post (among other things), and that the blog page should show the most recent 10 posts (with pagnation).

    1. I wiped out the custom Index loop that I made before. So there is no custom index loop anymore at all.
    2. I changed reading settings to be "Your latest posts" with "blog page shows at most" set to 10 posts.
    2. I reverted index.php back to the default one which comes with Thematic.
    3. I deleted the template I had previously created.

    With this set-up, when I hit the website, I see the 10 most recent posts with working pagnation. And the "Blog" link is broken. So here are the steps of what I think you've described.

    1. I copy template-page-blog.php from Thematic and renamed it template-page-mostrecentpost.php, with the title set to "Most Recent Post", and I change WP_Query to $wp_query->query( array( 'posts_per_page' => '1', 'paged' => $paged ) );

    2. In Wordpress, I create a page called "Homepage" and I select "Most Recent Post" as the template.

    3a. In Wordpress, under "Reading Settings", I change "Front page displays" to "a static page"
    3b. I set "Front page" to "Homepage"

    At this point, the homepage works fine. It shows the most recent post, and clicking "Older posts" shows the previous post with no problem. OK with pagnation.

    4. In Wordpress, I create a page titled "Blog". No template applied.

    5. In Wordpress, under "Reading Settings" and "a static page", I change "Posts page" to "Blog"

    So now, when you click on "Blog", the most recent 10 posts with no issue. However, clicking "Older posts" causes a 404 error still.

    What am I missing? :\
    If it helps any, I could care less if the homepage has pagnation or not. But it's required for the "Blog" page.

    Posted 11 years ago #
  17. well you seem to have picked up exactly what i was describing. if the blog page isn't working w/ just setting it as your "posts page" page via settings, then i would scratch that (don't select a recent posts page via reading settings) and just set the blog "page" to run the blog template. idk why that wouldn't be working though... you're sure you undid all your changes to home.php or index.php? either way, it doesn't seem worth the effort to solve when the default blog template should work instead, so try that.

    Posted 11 years ago #
  18. vicky515

    Ugh! So I was playing around with various things to see if I could get "Blog" working. It looks like removing the category base of "blog" fixed it. So now pagnation works, but now the posts don't start with "/blog/". Which I guess I can live with, but it still bothers me that it won't work since that's what it's intended to do...

    And now I've broken pagnation on the homepage, somehow... I don't think it's related to removing the category base though, I think I did something else while I was playing around. But I can't seem to figure out what, and I said that wasn't as important. I just gotta figure out how to remove the link now...

    Posted 11 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.