Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End [Solved] 2 loops, 2 categories – can I do this?

  • This topic is empty.
Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #26299
    bazzablue
    Participant

    Here’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

    #64878
    TheDoc
    Member

    You 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.

    #64880
    bazzablue
    Participant

    Maybe 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.

    #64881
    TheDoc
    Member
    #64887
    bazzablue
    Participant

    I 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.

    #64907
    Chris Coyier
    Keymaster

    look 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.

    #64910
    blue642
    Member
    Code:


    ” 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.
    The

    Code:

    areas are where you insert your parameters.

    #64930
    bazzablue
    Participant

    Guys,

    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.

    #64937
    bazzablue
    Participant

    All 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.

    #64938
    TheDoc
    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.

    #64939
    blue642
    Member

    That 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.

    #64962
    bazzablue
    Participant

    Good call. This is only a testing site so I wasn’t too worried about naming stuff helpfully.

    Thanks for your help again.

Viewing 12 posts - 1 through 12 (of 12 total)
  • The forum ‘Back End’ is closed to new topics and replies.