WordPress.org

Forums

[resolved] Show certain categorys at certain pages (31 posts)

  1. Kruuse
    Member
    Posted 4 years ago #

    Hi

    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?

  2. keesiemeijer
    moderator
    Posted 4 years ago #

    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:
    <?query_posts('cat=-3,-4'); >
    in this example the category blog-sticky has an ID of 4

  3. Kruuse
    Member
    Posted 4 years ago #

    Tyvm, I'll try that and I'll come back and tell how it worked out :)

  4. keesiemeijer
    moderator
    Posted 4 years ago #

    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.

  5. Kruuse
    Member
    Posted 4 years ago #

    Hi again

    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:

    Page.php: http://wordpress.pastebin.com/dXGKEXP9
    Index.php http://wordpress.pastebin.com/E2c0QH5c

    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 :)

  6. keesiemeijer
    moderator
    Posted 4 years ago #

    I made the changes to the files. You can find them here:
    page.php: http://wordpress.pastebin.com/1y9hwfYx
    index: http://wordpress.pastebin.com/K3BAMKBp

  7. keesiemeijer
    moderator
    Posted 4 years ago #

    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.

  8. Kruuse
    Member
    Posted 4 years ago #

    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.

  9. Kruuse
    Member
    Posted 4 years ago #

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

  10. Kruuse
    Member
    Posted 4 years ago #

    I just noticed that the blog posts, blog post sticky and the sticky post for news shows up at all other pages also.

  11. Kruuse
    Member
    Posted 4 years ago #

    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.

  12. keesiemeijer
    moderator
    Posted 4 years ago #

    I changed the page.php, maybe this will work.

    [edit]
    page.php http://wordpress.pastebin.com/H90muLds

  13. Kruuse
    Member
    Posted 4 years ago #

    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.

  14. keesiemeijer
    moderator
    Posted 4 years ago #

    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

    For myblog.php I made this custom template: http://wordpress.pastebin.com/RN5wB64w
    for page.php use this template: http://wordpress.pastebin.com/dXGKEXP9

  15. keesiemeijer
    moderator
    Posted 4 years ago #

    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.

  16. Kruuse
    Member
    Posted 4 years ago #

    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.
    Thanks again!

  17. Kruuse
    Member
    Posted 4 years ago #

    Hmm I didn't manage to find a way to solve it, seems like it's something with the index.php that makes the sticky post not on top. When I try with the original one it moves to the top.

  18. keesiemeijer
    moderator
    Posted 4 years ago #

    Ok I made a new index.php. we are going to do the same thing as on the blog page. Make a category home-sticky. And one post with this category will show on top. here is the template: index.php http://wordpress.pastebin.com/jHV92sKF After you made your home-sticky category get the ID and if it is not ID 5 look in your new index.php for this.

    <?php // category 5 = Home sticky - show one post
          $my_query = new WP_Query('cat=5&posts_per_page=1');
      ?>

    And change the cat=5 for the ID of home-sticky

  19. Kruuse
    Member
    Posted 4 years ago #

    Hi again, ty that worked, but it also shows up on the blog page.

  20. Kruuse
    Member
    Posted 4 years ago #

    Never mind I solved it :) Thank you again for your help

  21. BaronOfSweden
    Member
    Posted 4 years ago #

    Something happend under blog page http://www.kruu.se/?page_id=59
    No categorys and giant gap between headline and content of post.
    Anyone can see what's wrong?

    myblog.php :
    http://wordpress.pastebin.com/05NruRXu

  22. Kruuse
    Member
    Posted 4 years ago #

    At the index page the posts and category are working normal tho, but the blogg page is all messed up

  23. Kruuse
    Member
    Posted 4 years ago #

    didn't manage to solve it yet, tried to reinstall wordpress but then it only shows a white page., so I had to put back my old files.

  24. Kruuse
    Member
    Posted 4 years ago #

    Seems like it's the header that messed it up, I might be able to solv it

  25. keesiemeijer
    moderator
    Posted 4 years ago #

    I can't see the giant gap between headline and content of post and the categories are working normal on the blogg page.

  26. Kruuse
    Member
    Posted 4 years ago #

    I've been experimenting and had it fixed but then the main page was all messed up. If you check now you can see it: http://www.kruu.se/?page_id=59

  27. Kruuse
    Member
    Posted 4 years ago #

    and no categorys is shown.
    here's the header:

    http://wordpress.pastebin.com/99pxyEE9

  28. Kruuse
    Member
    Posted 4 years ago #

    I've noticed now that it works good in firefox and explorer, but in chrome, there's a big gap between the headline and the content. There's also no categorys. http://www.kruu.se/?page_id=59
    Think it go something to do with http://wordpress.pastebin.com/99pxyEE9

  29. Kruuse
    Member
    Posted 4 years ago #

    looked again, seems like it's not perfect in the other browsers either.
    The line with the time and date is missing in them too. but it's better thatn in chrome

  30. Kruuse
    Member
    Posted 4 years ago #

    but it works in index so must be in myblog.php http://wordpress.pastebin.com/RN5wB64w something is wrong

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.