• So, I searched through some of the pre-existing support forum posts to see if someone had attempted what I want to do. I noticed that several people have wanted multiple blogs on one page (and received advice), but they weren’t aiming for quite the same thing I am (of the threads I found, I mean).

    I have some visual aids to help show what I’m hoping to do:

    Here’s a mock-up I did in Photoshop of how I generally want the page to look like: https://i56.photobucket.com/albums/g174/Lederhosen404/wordpress_news_mockup-1.jpg

    And here’s the same image, but with blocks showing what goes where (you’ll likely need to look at this to have any idea of what I’m talking about below): https://i56.photobucket.com/albums/g174/Lederhosen404/wordpress_news_sections.jpg

    To clarify, DATE will be the date of the latest News blog post.

    Anyway, there will be three blogs:
    News
    Artist’s Blog
    Writer’s Blog

    For this discussion, we’ll say News is Category 1, the Artist’s Blog is Category 2, and the Writer’s Blog is Category 3.

    At the top, I want to show the News blog – usually the whole post (though I’ll likely end up using <!–more–> in the case of the post being too long to fit the space).

    Below that, I want to squish excerpts of the latest posts from the Artist’s and Writer’s blog, side by side.

    I’m thinking I will have to make a Page that “calls” the latest posts from the blogs’ respective categories, and places them in the correct area (I’m guessing CSS span or div tags will suffice in telling the blogs where to go and how much space they have.) We’ll call this Page “News Home”; its template’s name will be news_home.php.

    I assume that using the <!–more–> tags inside posts for the Artist’s Blog and Writer’s Blog categories will make sure only an excerpt shows up on News Home. That’s what it says in the Docs, anyway ??

    However, when the excerpt is displayed, I don’t want the title of the post to show up. Instead, I want the title of the blogs to show up. I’m thinking I might be able to simplify this by making the blog titles graphics in the template – instead of text – and asking WordPress to only call up the_content of the latest post of the Artist’s or Writer’s Blog.

    Multiple Loops!

    Alright, so, after reading through the Docs about Multiple Loops, I think I have a least a slight grasp on the concept. You can call up the Loop however many times you want, but can only call $wp_query once. So, this results in the coder needing to put in some work-arounds for every Loop after the first. They give two examples of how to do this in the Docs, but I’m not quite sure which is the best for my situation.

    Using query_posts seems less convoluted than the $temp_query/$wp_query swap solution, but can someone tell me which is more efficient? Like, which – if either – would put more stress on the server or user? Would either cause worse of a slow down than the other?

    Now comes the part where I reveal what a PHP/CSS newb I am and take a stab at how I might go about coding all this. If anyone out there can correct me or offer a better solution, I would deeply appreciate it.

    For the following, assume I have already set up some div ids to tell the three posts, the date, and the news title how to format themselves on News Home. They will be appropriately named: news_date, news_title, news_post, artist_post, writer_post

    In news_home.php:

    <?php query_posts('category_name=news&showposts=1'); ?>
    <?php if (have_posts()) : ?>
                   <?php while (have_posts()) : the_post(); ?>
    
             <div id="news_date">
                   <?php the_date(l, F jS, Y); ?>
             </div>
    
             <div id="news_title">
                   <?php the_title(); ?>
             </div>
    
             <div id="news_post">
                   <?php the_content('Read more...'); ?>
             </div>
    
         <?php endwhile; ?>
    
    <?php query_posts('category_name=artist_blog&showposts=1'); ?>
    
             <div id="artist_post">
                   <?php the_content('Read more...'); ?>
             </div>
    
         <?php endwhile; ?>
    
    <?php query_posts('category_name=writer_blog&showposts=1'); ?>
    
             <div id="writer_post">
                   <?php the_content('Read more...'); ?>
             </div>
    
         <?php endwhile; endif; ?>

    This is working on the assumption that news_home.php would actually be index.php. Does anyone know how I would create the same functions if it WASN’T index.php? The Docs say that using query_posts outside of the main page is generally a bad idea, so I’m curious to know.

    Er… At any rate, the point of this post is to make sure my logic in this is sound. If there’s anything that needs fixing, or could be done better, I’d like to know! Thanks!

    (p.s., I’m using WordPress 2.7.1, and PHP 5 on my server)

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter lederhosen

    (@lederhosen)

    Can someone please help me out here? My code failed epically, and I don’t think I’m “getting” multiple loops, as my continued attempts to get this code to work have also been failing.

    I’m not particularly a genius with WordPress’ functions, but I’ll have a go at it.

    It looks to me like you should be running the loop after you run query_posts for every category you want to call.

    This is how I think it should look:

    <?php query_posts('category_name=news&showposts=1'); ?>
    <?php if (have_posts()) : ?>
                   <?php while (have_posts()) : the_post(); ?>
    
             <div id="news_date">
                   <?php the_date(l, F jS, Y); ?>
             </div>
    
             <div id="news_title">
                   <?php the_title(); ?>
             </div>
    
             <div id="news_post">
                   <?php the_content('Read more...'); ?>
             </div>
    
         <?php endwhile; endif; ?>
    
    <?php query_posts('category_name=artist_blog&showposts=1'); ?>
    <?php if (have_posts()) : ?>
                   <?php while (have_posts()) : the_post(); ?>
    
             <div id="artist_post">
                   <?php the_content('Read more...'); ?>
             </div>
    
         <?php endwhile; endif; ?>
    
    <?php query_posts('category_name=writer_blog&showposts=1'); ?>
    <?php if (have_posts()) : ?>
         <?php while (have_posts()) : the_post(); ?>
             <div id="writer_post">
                   <?php the_content('Read more...'); ?>
             </div>
    
         <?php endwhile; endif; ?>

    Let me know if that works.

    Thread Starter lederhosen

    (@lederhosen)

    No such luck, I’m afraid, but your assistance and time is appreciated!

    Just a few moments ago, I ran into this tutorial for Triple Loops: https://perishablepress.com/press/2006/11/22/perishable-press-triple-loop-for-wordpress/

    I highly suggest it for anyone who’s having trouble getting multiple Loops to function correctly. I would have found this much quicker if I had Google searched “triple loop” instead of “multiple loops” or “three loops”. Dur.

    So far, I’ve applied my conditionals (what Categories I want to show up, how many posts, etc.) to the code the tutorial above provides, and everything seems to be working. I’ll keep things updated here!

    I just pulled the code from one of my sites where I run multiple loops. Here is how I’ve got the code set up:

    <?php query_posts('cat=-5&showposts=5'); ?>
         <ul>
    	<?php while (have_posts()) : the_post(); ?>
    	<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
    	<?php endwhile;?>
         </ul>
    <?php endif; ?>

    So I think the mistake I made last time was keeping have_posts even though query_posts takes its place.

    <?php query_posts('category_name=news&showposts=1'); ?>
         <?php while (have_posts()) : the_post(); ?>
    
             <div id="news_date">
                   <?php the_date(l, F jS, Y); ?>
             </div>
    
             <div id="news_title">
                   <?php the_title(); ?>
             </div>
    
             <div id="news_post">
                   <?php the_content('Read more...'); ?>
             </div>
    
         <?php endwhile; endif; ?>
    
    <?php query_posts('category_name=artist_blog&showposts=1'); ?>
         <?php while (have_posts()) : the_post(); ?>
    
             <div id="artist_post">
                   <?php the_content('Read more...'); ?>
             </div>
    
         <?php endwhile; endif; ?>
    
    <?php query_posts('category_name=writer_blog&showposts=1'); ?>
         <?php while (have_posts()) : the_post(); ?>
             <div id="writer_post">
                   <?php the_content('Read more...'); ?>
             </div>
    
         <?php endwhile; endif; ?>

    You can do this with two plugins:

    1. Blog in Blog
    2. Pages Posts

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Three Blogs, One Page’ is closed to new replies.