Three Blogs, One Page
-
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 BlogFor 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)
- The topic ‘Three Blogs, One Page’ is closed to new replies.