- This topic is empty.
-
AuthorPosts
-
September 30, 2009 at 3:22 pm #26299
bazzablue
ParticipantHere’s what I would like to do:
On the left hand side of my home page to have a list of my 5 latest posts that would have the category of Blog and in the centre to have a list of my 3 latest posts with the category of Portfolio. Both sections would be styled differently and would take visitors to two separate sections of the site – Blog and Porfolio – which would look very different from one another.
I have had a look around the web for this but most of the searches that show for multi loops seem to deal with having a featured post displaying different from the posts below.
Is what I am wanting to do possible? I am fairly new to WordPress and my knowledge of PHP is very, very limited.
Thanks for any help.
Barry
September 30, 2009 at 4:19 pm #64878TheDoc
MemberYou simply are going to have two loops on the page, as far as I know there is no problem with that.
If you’re comfortable doing one loop and one category, doing a second should be as easy as copy-paste.
September 30, 2009 at 4:29 pm #64880bazzablue
ParticipantMaybe my understanding of the loop is not very clear. I tried doing that but my page didn’t show anything apart from some error message. Probably didn’t specify category properly.
An extra issue is that I am not wanting to use index.php as my home page, so I need to have a Blog index page and another index page for Portfolio.
With my limited knowledge I may be biting off more than I can chew.
September 30, 2009 at 4:39 pm #64881TheDoc
MemberHere’s one post that I found:
http://wordpressmodder.org/multiple-loo … .html#hide
And here’s one with three loops:
September 30, 2009 at 5:17 pm #64887bazzablue
ParticipantI did come across the Perishable Press one but was a bit daunted by it and wasn’t sure it was what I needed.
Will give it a go on a test site and see where I get with it.
Thanks for your help.
September 30, 2009 at 10:34 pm #64907Chris Coyier
Keymasterlook into the query_posts function. That’s what you’ll need to call before the loop to set the category and number of posts. Set it once for the first loop, run the loop, set it again, run the second loop.
October 1, 2009 at 12:00 am #64910blue642
MemberCode:
” rel=”bookmark” title=”Permanent Link to “>Not Found
Sorry, but you are looking for something that isn’t here.
” rel=”bookmark” title=”Permanent Link to “>Not Found
Sorry, but you are looking for something that isn’t here.
Here is a typical double loop in action with query_posts as Chris mentioned, a modification of what I used on my last test blog.
It creates two divs, where each holds the sections you talked about creating.
TheCode:
areas are where you insert your parameters.
October 1, 2009 at 7:46 am #64930bazzablue
ParticipantGuys,
Thanks for the help so far. I have made some progress on a (very badly designed) http://www.bazzasblog.co.uk.
As you can see the home page displays two loops – one for Blog and the other for Portfolio. I have managed to edit the code on the index.php so it only shows up the bolg category posts. I did this by entering <?php query_posts("category_name=blog"); ?>.
What I know need to do is create another index.php page with <?php query_posts("category_name=portfolio"); ?> inserted. Obviously this isn’t going to be that simple as I can’t create another page.
What do I do? Can I create index2.php? If so, how do I point the Portfolio entries to that page? And how do I get these entries to show up on my Portfolio ‘page’?
Thanks again for your help. And Chris thanks for all your tutorials and screencasts – they have taught me so much.
October 1, 2009 at 11:55 am #64937bazzablue
ParticipantAll sorted. I saved the index.php as index2.php. Made it a template and set the category for Portfolio posts only.
To my surprise it worked!
Now on to custom fields for the Portfolio items.
October 1, 2009 at 12:01 pm #64938TheDoc
Member"bazzablue" wrote:All sorted. I saved the index.php as index2.php. Made it a template and set the category for Portfolio posts only.You should try to give the file name a little more importance, something like "static-home.php" or "home-page.php", something like that. "index2.php" could be confusing later on, especially with index.php kicking around.
October 1, 2009 at 12:07 pm #64939blue642
MemberThat is the proper way to do it, unless you are going to reuse that template page though, I’d suggest naming it something like portfolio.php to better keep track of things as you go. Index2.php is not very descriptive. Also, when you declare the template name, you should name it something cohesive live "Portfolio" or "portfolio-template"
As far as the query_posts code though, I ran in to a situation where when the Page was not the index page, it would not respect the read more links, but just show the entire post. (You may experience this) I never bothered to fix it… Just a heads up as far as that goes.
October 2, 2009 at 6:22 am #64962bazzablue
ParticipantGood call. This is only a testing site so I wasn’t too worried about naming stuff helpfully.
Thanks for your help again.
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.