I’m working on a site, http://www.kruu.se
I want my news category to only shows at the page “Hem”, the other categorys I want under the “Blogg” page. I would also want a welcome post that is above the other postes both at “Hem” and at “Blogg” (but diffrent content).
Now as you can see all my blog post shows at the home button “Hem”
I hope you can understand how I want it.
Anyone know how to do this?
For your “Hem” posts you have to do a post query. In your theme’s index.php put this above your loop:
<?query_posts('cat=3'); >if your news category has a category ID 3.
To make a welcome post on the home page make a post sticky. It wil show on top.
On page.php (Blog – all other posts) you have to do multiple loops. Make a category of “blog-sticky” and give this category to the post you want to show up on top.
for the first loop (blog-sticky) put this right before the loop:
<?php $my_query = new WP_Query('cat=4&posts_per_page=1'); ?>
and begin your loop with this:
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
for the second loop (all other post minus news and blog-sticky) put this right before the loop:
in this example the category blog-sticky has an ID of 4
Tyvm, I’ll try that and I’ll come back and tell how it worked out 🙂
Very good. If it doesn’t work out you can always put the code of your theme’s index.php and page.php in the pastebin and provide links back to them here.
I’ve tryed and tryed but can’t get it to work, to be totally honest I didn’t even know from the beginning what a loop was. But I think I know now after talking to some ppl, but I still couldn’t get it to work.
I hope it’s not too much to ask for, if you could help me:
The sticky category for news is id 5
The sticky category for blog is id 4
The category for news is id 3
The blog have side order 3 (don’t know if that matters)and it says page ID 59 when I press it
Guess I gonna have to try to make those category not visible in the sidebar with the other categorys later, but that’s another question 🙂
To make a post sticky on the homepage there is no need to give it the category “news-sticky” (5). Just make the post stickey and it will show up on top. Sticky posts are only working on the homepage and not on a normal page, that’s why we have to make “blog-sticky” category for the normal page. This is good tutorial for making posts sticky.
Thank you very much, the code seems to work great. I tried to make a post sticky at the first page but seems like the newer ones get’s above it anyway.
Noticed now that it seems like the sticky ones in news category appears at the blog page also even if they shouldn’t, the non sticky one from the news category works as they should and don’t show up at the blog page tho
I just noticed that the blog posts, blog post sticky and the sticky post for news shows up at all other pages also.
I can’t see anything about the page ID in the code, shouldn’t there be something that shows that the blog post and sticky blog post will be seen under page ID 59? It wouldn’t explain why the sticky news shows in all other pages and the sticky news don’t shown on top tho.
I changed the page.php, maybe this will work.
Sticky news doesn’t show up at other pages than the main page now, that’s good. But the sticky post at the main page do not show up on top and the other blog posts still shows at all other pages instead of just under blogg page ID 59.
other blog posts still shows at all other pages
Other pages use the same page template (page.php) as the page with ID 59?. You have to make a custom page template for your “blog” page called myblog.php
and use the normal page template page.php for normal pages
After that you have to give the blog page (id 59) the template: blog-template. You do this when you edit that page, Under Page Attributes you can change the template. And Update the page.
That worked just great, thank you so much for taking you time to help me I really appreciate it.
The only thing not working is the sticky news post that won’t stay on top, but I can try to see if I can google it or replace it with some kind of plugin.
- The topic ‘Show certain categorys at certain pages’ is closed to new replies.