WordPress.org

Ready to get started?Download WordPress

Forums

hide an post on main page (28 posts)

  1. missy_tommen
    Member
    Posted 8 years ago #

    Is there any chance i can hide an post on the main page, and make it show in an page?

  2. w3central
    Member
    Posted 8 years ago #

    Is this post one that you have made and will never change, or a dynamic one, let's say every 2nd post in a certain category?

  3. missy_tommen
    Member
    Posted 8 years ago #

    No, i mean, if i post in a spesial category, i will that this category should be pubished in one page. and not on the main page. :) if you understand ?

  4. w3central
    Member
    Posted 8 years ago #

    For me, the best way to achieve this seems by using conditionals in the loop.

    Example from the codex:

    <?php if ( !(in_category('3') && is_home()) ) { ?>

    Will cause posts from category 3 not to display on the homepage. They will display however when you look at the archives, eg http://www.yoursite.com/archives/category3/.

    The codex is really helpful here.

    http://codex.wordpress.org/The_Loop

  5. missy_tommen
    Member
    Posted 8 years ago #

    Im not that good in "programing php" that i understand that :( yet.. But, lets say that i will post in an category called "test".. And all posts in that category should NOT been posted in main page.

    Then i create an new page. Called "test view", and in that page i want the posts i posted under the "test" categroy to show.

    What php code should i add to the page "test view" and what php code should i edit/remove in index.php ?

    Please help me here :)

    Thanks!

  6. w3central
    Member
    Posted 8 years ago #

    Not showing category 'test' in the index page is easy. Look at the code that says:

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

    That's the start of the loop. Add

    <?php if ( !(in_category('3') && is_home()) ) { ?>

    after that to only show posts that don't belong to category 'test'. To know which category id 'test' has look in your categories tab. Also add

    <?php } ?>

    right before

    <?php endwhile; else: ?>
    <?php _e('Sorry, no posts matched your criteria.'); ?>
    <?php endif; ?>

    The second, more difficult problem is with having a page that displays posts. Unless you write a plugin that won't work. There are other ways to do it though.
    One possibility is not to use a page, but style the archives for category 'test' like you would do with the page.
    Another possibility is to create a new page template. But that would involve knowledgde op php.

  7. moshu
    Member
    Posted 8 years ago #

    It is not difficult at all!
    Just don't think in Pages. If you provide a link to that excluded catgeory, e.g.
    example.com/blog?cat=3 - it will only display the posts from that category and you don't have to do anything.

    However, if you need that webpage - showing the posts from the "test" category - to look a bit different, you just have to create a category template.

    Guys, don't over-complicate things that are already solved and easy to do with WP's native features :)

  8. w3central
    Member
    Posted 8 years ago #

    Uhm, you give exact the same advice as I have given. So if I'm overcomplicating things... =)

    Also, because she doesn't understand php, it's rather difficult for her.

  9. moshu
    Member
    Posted 8 years ago #

    The second, more difficult problem is with having a page that displays posts. Unless you write a plugin that won't work.

    Yes, this is over-complicating it. Clicking on a category link - it just displays posts from a category. No plugin, no difficulties.

  10. w3central
    Member
    Posted 8 years ago #

    Right under what you quoted:

    There are other ways to do it though.
    One possibility is not to use a page, but style the archives for category 'test' like you would do with the page.

    Btw, if she really wants to have a page, a plugin or page theme is necessary. The other option I gave is the same as you did.

  11. moshu
    Member
    Posted 8 years ago #

    But to have/use a page for that... it's quite an idiotic idea when you have built-in tools to do it.
    Sometimes new users don't know about it, that's why they start thinking in the wrong direction, and encouraging it - I consider a bad policy. Put them on the right (and easy) track.

  12. w3central
    Member
    Posted 8 years ago #

    I haven't encouraged it. On the contrary, have pointed to the problems with that approach.

    Let's listen to what missy_tommen says about it and wether she has a good reason to prefer pages or if a link to the archives (with or without custom makeup) suffice.

  13. missy_tommen
    Member
    Posted 8 years ago #

    [offtopic] 'shes a he' ;) [/offtopic]

    I see that i could use the category list. But wouldnt 'Archive for test' display in the top of that page if you browse categories?

    If so, i could remove it with CSS? That would help me :)

    And, then i need to make an link to the category along with the other links in the "menu".

    I can a bit of php, but not as much as i want to. Doh i understand what you are talking about :)

    EDIT: don't think you would understand anything on my webpage (Norwegian) but maybe it helps to see the page: http://www.sportsklubben.no/alag

  14. Ronny
    Member
    Posted 8 years ago #

    hey guys. still no solution for hiding a post on the main page, but making it show up in the Archives and NOT affecting the number of posts on the main page?

    as taken from the the loop section of the codex

    ...
    <?php if ( !(in_category('3') && is_home()) ) { ?>
    ...

    This will ensure that posts from Category 3 will only be excluded from the main page. There are other Conditional Tags that can be used to control the output depending on whether or not a particular condition is true with respect to the requested page.

    Please note that even though the post is not being displayed it is still being counted by WordPress as having been shown -- this means that if you have WordPress set to show at most seven posts and that two of the last seven are from Category 3 then you will only display five posts on your main page. If this is a problem for you, there is more complicated hack you can employ described in the Layout and Design FAQ.

    unfortunately this is a problem for me. any ideas?

  15. w3central
    Member
    Posted 8 years ago #

    "But wouldnt 'Archive for test' display in the top of that page if you browse categories?"

    You can try this out on your own page. I see (or I think I see) you have 3 categories. When I click on one I don't think there's a finnish word for archives on top (or maybe I'm mistaken). In any case, if it would appear that could easily be solved. But as far as I see this problem doesn't exist with your template.

    "And, then i need to make an link to the category along with the other links in the "menu"."

    It could be as easy as that yes. Adding a list item with a link to your test category.

  16. w3central
    Member
    Posted 8 years ago #

    @ronny

    It's easier when you post in a new thread as to keep the discussions seperate.

    "unfortunately this is a problem for me. any ideas?"

    In what way is it a problem? It doesn't work for you? What does it do that you don't want or what does it not do what you want?

  17. missy_tommen
    Member
    Posted 8 years ago #

    w3central:

    Thanks, you have helped me a lot here!

    But, i've edited the index.php file for my template VERY much. And now i don't have any archives file at all..

    Cause the archive.php who is placed under 'default' template was edited inside the index.php. But i needed to remove this feature :( It wouldnt work with the modifications i made for 'removing category on main page'... Unfortunately..

  18. Ronny
    Member
    Posted 8 years ago #

    hi w3central.
    if you read the blockquote i helpfully provided just to avoid this kind of further debate, it says towards the end

    If this is a problem for you, there is more complicated hack you can employ described in the Layout and Design FAQ.

    my references to this being a problem was to this. i meant, in my case, this IS a problem. in that i cannot allow the number of posts in my main page to decrease beacuse of the "invisible" posts i have "hidden" are pushing back all the posts on my main page. the reason i did not say this is because i do not believe this statement simplifies thigns at all, and i i hoped peoploe would notice the block quote i provided.

    as for not starting a new topic. i understand how annoying forum posters can be. demanding help NOW. wanting this NOW wanting that NOW. i try to avoid this, and i have been absolutely civil and undemanding in my requests, but there really is no pleasing you.
    if i posted a new topic, you would probably just direct me to this thread. hence i have replied to this thread, even though the possibility of someone reading it would be even less than if i hate made its own thread, just in the interests of keeping the board neat.

    if i have erred in this too i apologize sincerely. now do you think we can get on with answering the question?

    thank you.
    Ronny.

  19. w3central
    Member
    Posted 8 years ago #

    @missy_tommen

    You don't need an archive.php. The archives for a category are displayed in this url http://www.sportsklubben.no/alag/?cat=(fill in category id here)

  20. w3central
    Member
    Posted 8 years ago #

    @ronny

    If I understand you correctly, you just want less posts to appear on the main index page, eg only the latest 5?

  21. Ronny
    Member
    Posted 8 years ago #

    hi w3central
    no what i'm looking for is to hide a series of posts from the main page, but making sure they still show up on the archives and their category page (i.e for category 3 http://www.yoursite.com/category/3 all the posts show up here)

    "private post" doesn't get the job done.

    thank you.

  22. w3central
    Member
    Posted 8 years ago #

    Didn't this help?:

    Look at the code that says:

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

    That's the start of the loop. Add

    <?php if ( !(in_category('3') && is_home()) ) { ?>

    after that to only show posts that don't belong to category 'test'. To know which category id 'test' has look in your categories tab. Also add

    <?php } ?>

    right before

    <?php endwhile; else: ?>
    <?php _e('Sorry, no posts matched your criteria.'); ?>
    <?php endif; ?>

  23. Ronny
    Member
    Posted 8 years ago #

    this does help hide posts on the main page while making them show up in the archives but it also pushes down the posts on the mian page as though the posts were not hidden, which is "a problem for me"

  24. w3central
    Member
    Posted 8 years ago #

    "it also pushes down the posts on the mian page as though the posts were not hidden"

    sorry, I don't quite get what you mean here

  25. digitaldave2
    Member
    Posted 8 years ago #

    Where do we place this code for it to work correctly?

    <?php if ( !(in_category('3') && is_home()) ) { ?>

  26. digitaldave2
    Member
    Posted 8 years ago #

    Where does this go? In the index.php page?

    Didn't this help?:

    Look at the code that says:

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

    That's the start of the loop. Add

    <?php if ( !(in_category('3') && is_home()) ) { ?>

    after that to only show posts that don't belong to category 'test'. To know which category id 'test' has look in your categories tab. Also add

    <?php } ?>

    right before

    <?php endwhile; else: ?>
    <?php _e('Sorry, no posts matched your criteria.'); ?>
    <?php endif; ?>

  27. digitaldave2
    Member
    Posted 8 years ago #

    I inserted the provided code into my index.php page but it gets stuck in a loop outputting over and over again.

    Is there anyone that's ever done this that can explain it?

  28. Ronny
    Member
    Posted 8 years ago #

    dave. you should put it between

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

    <!-- The following tests if the current post is in category 3. -->
    <!-- If it is not, the code within The Loop is executed as normal. -->
    <!-- If it is, nothing is done until the next post is processed. -->

    and

    <div class="post">

    go here http://codex.wordpress.org/The_Loop
    and read the section Exclude Posts From Some Category

    for complete coding details.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags