• Resolved Kruuse

    (@kruuse)


    Hi

    I’m working on a site, https://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?

Viewing 15 replies - 1 through 15 (of 31 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    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

    Thread Starter Kruuse

    (@kruuse)

    Tyvm, I’ll try that and I’ll come back and tell how it worked out ??

    Moderator keesiemeijer

    (@keesiemeijer)

    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.

    Thread Starter Kruuse

    (@kruuse)

    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: https://wordpress.pastebin.com/dXGKEXP9
    Index.php https://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 ??

    Moderator keesiemeijer

    (@keesiemeijer)

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

    Moderator keesiemeijer

    (@keesiemeijer)

    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.

    Thread Starter Kruuse

    (@kruuse)

    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.

    Thread Starter Kruuse

    (@kruuse)

    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.

    Thread Starter Kruuse

    (@kruuse)

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

    Thread Starter Kruuse

    (@kruuse)

    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.

    Moderator keesiemeijer

    (@keesiemeijer)

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

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

    Thread Starter Kruuse

    (@kruuse)

    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.

    Moderator keesiemeijer

    (@keesiemeijer)

    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: https://wordpress.pastebin.com/RN5wB64w
    for page.php use this template: https://wordpress.pastebin.com/dXGKEXP9

    Moderator keesiemeijer

    (@keesiemeijer)

    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.

    Thread Starter Kruuse

    (@kruuse)

    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!

Viewing 15 replies - 1 through 15 (of 31 total)
  • The topic ‘Show certain categorys at certain pages’ is closed to new replies.