WordPress.org

Ready to get started?Download WordPress

Forums

Multiple Pages with Multiple Posts from Multiple Categories? (24 posts)

  1. dcochran
    Member
    Posted 7 years ago #

    Is it possible to have multiple pages (or sections of the wordpress site) that display posts from multiple categories? My index does it great. I've used multiple versions of the loop in the index.php, each loop configured to display posts from a specific category.

    Now I want other pages in the site that can do it, too.

    We're building a college student website. I would like for each major section of the site to be able to be laid out like we've laid out the current index page, with posts from this category in one spot, posts from another category in another, and so on.

    http://okwueagle.com/

  2. bryan868
    Member
    Posted 7 years ago #

    You'd basically do the same thing that you did in your index.php. Just create static .php files: academics.php, campus.php, etc., and insert your multiple loops to achieve the desired effect. That's how I'd approach it.

  3. dcochran
    Member
    Posted 7 years ago #

    Thanks. I'm trying that out. I'm having trouble.

    I've created a stepup.php based on index.php and saved it in the same theme folder as my functioning index.php.

    I have two problems:

    1) The URL to get to this file is very long and unwieldy.

    2) The template tags aren't connecting to the database. I get an error on each bloginfo item in the head ... and so I got read of those, replacing them with straight code. Now it gets to the loops, but the loops aren't working. I get error messages every time.

    Fatal error: Call to undefined function: have_posts() in /home/.pause/okwueagle/okwueagle.com/wp-content/themes/okwueagle-spring07/stepup.php on line 14

    Here's the URL to this file.

    http://okwueagle.com/wp-content/themes/okwueagle-spring07/stepup.php

    How can I solve these two issues?

  4. dcochran
    Member
    Posted 7 years ago #

    Just checking back -- Is there a way to do this?

  5. dcochran
    Member
    Posted 7 years ago #

    Did I stump the community?

  6. moshu
    Member
    Posted 7 years ago #

    I guess nobody really understands what you want - at least I don't. So, instead of bumping just try to clarify what are the "multiple" pages. Until we understand the structure of your content... nobody will be able to say anything that would make sense.

  7. nhlline
    Member
    Posted 7 years ago #

    I think I get what he wants. You know how your front page shows multiple posts, usually the 10 most recent, and then you can click previous pages for more, can you have this for ALL pages throughout your website?

  8. moshu
    Member
    Posted 7 years ago #

    nhlline,
    you are making it it even more confusing :)
    If you visit the OP's WP install - there is nothing similar to what you said.

  9. nhlline
    Member
    Posted 7 years ago #

    Can you make a page with more than one post? That simple.

  10. moshu
    Member
    Posted 7 years ago #

    On a basic WP install - no. Pages (if we are talking about the same thing!) are meant to display ONE entry from the DB.

  11. nhlline
    Member
    Posted 7 years ago #

    Yes thats what I'm talking about. Thanks for clearling that up but why not, it would make wordpress that much better. And please refer to my post on "WordPress 2.1" I have a question in there that is frustrating me to no end.

  12. moshu
    Member
    Posted 7 years ago #

    29 minutes (the time since you posted that topic) is nothing... in terms of WP forum. When you didn't get an answer for 24 hours - you may start thinking why people didn't get it, and add some more info :)

  13. nhlline
    Member
    Posted 7 years ago #

    lol Thanks for the info

  14. dcochran
    Member
    Posted 7 years ago #

    Thanks to all for jumping back in here with me.

    To try to make it more specific:

    My current index.php places posts of category sub-features within a sub-features div which I position in the top left sidebar. Under that I have a loop pulling posts of category announcements. Then I have a loop pulling posts of category features, which I've positioned at the top of the center column. Under features is a loop pulling posts from the category Homepage Highlights ... and on it goes.

    Now I want MORE such files, in which I pull posts from multiple categories and place them in various places on the same web page. I do not need to create these as WordPress pages. I only want to be able to make a copy of index.php and change up the categories of the posts which get pulled in by the various loops.

    Besides index.php, I would like to have campus-life.php that does this, and academics.php, and eventually more. Each of these would have a complex layout, like my current index.php -- placing posts from various categories in various places on the web page.

    I've tried this, but the loops don't work. And when I place the file in the theme folder, the URL goes to the file in the theme folder (which is extraordinarily long and awkward), and the loops still don't work.

    Is there a way to tell wordpress to treat these new multi-category template files like it treats index.php? -- connecting it to an address on the main site structure (i.e., http://okwueagle.com/campus-life.php) -- and allowing it to pull posts from multiple categories into various places in the same page?

    By the way, there is no 404 page working yet (I'm working on that), and so when you go to a page that isn't there, you get the index:

    http://okwueagle.com/

  15. dcochran
    Member
    Posted 7 years ago #

    And so to clarify, what I get when I try to do this as bryan868 first suggested is this.

  16. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    Okay, you cannot connect *directly* to a theme file like that. There's your first mistake.

    What we're trying to figure out is how yowant people to actually access these extra loops. Where are they going to be? How are you wanting to link to them?

    You said I do not need to create these as WordPress pages., but in point of fact, yes, actually you do. Only WordPress pages can access WordPress data.

    If these extra php files you made have Loops in them that explicitly use get_posts or WP_Query or whatever to get what posts they want and such, then you should be able to simply turn them into Page Templates and then create new Pages (which will be empty) which use those Page templates. Then they will be accessible as standard WordPress pages.

    First read this:
    http://codex.wordpress.org/Pages#Creating_your_own_Page_Templates

    Next, turn one of your php files into a Page Template by adding the appropriate header to it.

    Then, create a new Page using Write->Page.

    Select your template on the right.

    Publish.

    Your Page will now be accessible at http://example.com/Pagename .

    Is there a way to tell wordpress to treat these new multi-category template files like it treats index.php? -- connecting it to an address on the main site structure (i.e., http://okwueagle.com/campus-life.php) -- and allowing it to pull posts from multiple categories into various places in the same page?

    See, you're confused about the way wordpress works. It doesn't magically turn links on the main site into links in the theme folder. The index.php on the main site *actually exists*. It loads the blog. In point of fact, it *always* loads the blog, regardless of what the URL is in the address bar. It uses URL rewriting, and the content of the address does not refer to the actual directory structure of the site in any way at all.

    Forget the old ways you know about putting html in folders and building a folder structure to create different URLs. WordPress does not work that way.

  17. dcochran
    Member
    Posted 7 years ago #

    Otto42,
    I understand what you've suggested. I've read all about pages, I've created new page templates, and I have selected these templates for new WordPress Pages.

    What these pages will not do is pull posts from multiple categories into the same page. This is what I want to be able to do.

    I know WordPress does not typically do this. I want to know if there is a way to make WordPress do this. Apparently I've got to do some hacking. How do I hack it and where?

    As for what kind of loops I am using -- they are loops which begin like this.

    
    <?php if (have_posts()) : ?>
    		<?php while (have_posts()) : the_post(); ?>
    <?php if (in_category('5') ): ?>
    

    Each one is set to pull posts from a specific category. I have several of these loops running in the index.php, each with a different category number, and together they populate my homepage with multiple posts from multiple categories, each in its own section of the homepage.

    Now I want other pages, besides just the homepage, which also enable me to fill out the page with various sections, each section populated by posts from a different category. Thus, these other pages will, like my index, contain multiple posts coming from multiple categories. I am assuming these can't be WordPress Pages, and they can't be category archives -- or if they can be, then I have to modify the way WordPress works.

    Where do I modify, and how?

  18. moshu
    Member
    Posted 7 years ago #

  19. dcochran
    Member
    Posted 7 years ago #

    moshu -

    That looks like it's more on track. I'll try it out and see ...

  20. moshu
    Member
    Posted 7 years ago #

    You can also search the forum, now that I understand what you want I remember similar threads.
    The issue is that WP recognizes Pages as Pages - meaning it knows that only ONE DB entry (post/whatever) should be shown on it.
    What you need, to tweak your queries in a way to set the "is_page" thing as false > so that WP will let you to display whatever you want.
    The solution I linked above seems to solve that AND keeping the beginning and the end of the file as a Page (in case you need conditionals based on that status).

    Sorry, I am not a coder, so I can't give you code lines, but I think I understand how it works ;)

  21. dcochran
    Member
    Posted 7 years ago #

    Yes! That's the kind of stuff I'm needing. Thank you. I'll dig around, try it out, and report back.

  22. Root
    Member
    Posted 7 years ago #

    I notice the WP credits are not showing.

  23. dcochran
    Member
    Posted 7 years ago #

    Sorry. We're working on the footer now and will get those in!

    I do want folks to know we're doing this with wordpress. Just been trying to get the thing fully functional and lost track of that. Thanks for the prod.

  24. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    You can have a Loop on a page that will show categories and posts and such. But you don't get it for free.

    See, this loop:

    <?php if (have_posts()) : ?>
    		<?php while (have_posts()) : the_post(); ?>
    <?php if (in_category('5') ): ?>

    Is a normal loop. What you need is something where you specify exactly what you want. Try something more like this:

    <?php $my_query = new WP_Query('category_name=Your_category&showposts=10'); ?>
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
      <!-- Do your loop here... -->
    <?php endwhile; ?>

    That is what I mean by a specific loop. You control the loop, from beginning to end, instead of trying to use the default loop created for you (which will get the Page content). With this, you get exactly what you specify, nothing else.

Topic Closed

This topic has been closed to new replies.

About this Topic