- This topic is empty.
April 7, 2010 at 12:12 pm #28648
I’m wondering if there is a way to choose which of your pages a post will appear on. Is there a snippet of code or a plugin that lets me do this?April 7, 2010 at 2:45 pm #73621
Most certainly. You’ll want to make sure to assign each post with the proper category. Then, depending on how your templates are set up, you can have a page show only certain categories.
Let’s say you have 3 pages: Hockey, Cake, and Money.
If they all use the same template (eg, page.php), then you’ll need to do something like:
if page Hockey then > show posts from category "hockey";
if page Cake then > show pasts from category "cake";
This is a slightly more complicated piece of code than what is below, so let me know which one you need before I attempt at explaining! haha
If the are using different templates (eg, hockey.php, cake.php, money.php), then you simply need to run one single loop with a query like so (‘5’ is the category id, replace that number):Code:
(that was from the snippets section, btw)April 7, 2010 at 3:39 pm #73626
Thanks for the help. I missed that snippet when I looked through. I would have a separate page for each, so I do only need the one loop, and then just change it on each page.
This made me think of a follow-up question though, how would you exclude a specific category if you don’t want it on a page?
Again, thank you for the help.April 7, 2010 at 4:18 pm #73631
Remember, you’re not editing the pages themselves within WordPress, you’ll need to edit the actual template (which looks like, in your case, is page.php).
Can you confirm that all pages you’d like to do this on are all using the same template?
You can do all sorts of wonderful queries, including excluding a category. Check out the WordPress Codex for all of your answers on the matter:
If the answer to your question above is "yes", then we can discuss exactly what you’d like to accomplish!April 7, 2010 at 4:24 pm #73581
No, they all aren’t using the same template. Each page is a custom page.php. I can edit the loop on any of page the way I want.April 7, 2010 at 5:20 pm #73636
Excellent, that makes things even easier!
Do you get how the query_posts function works?April 7, 2010 at 5:32 pm #73637
Yes. I do. And thank you very much. That link was also very helpful too.
- The forum ‘Back End’ is closed to new topics and replies.