hide an post on main page
-
Is there any chance i can hide an post on the main page, and make it show in an page?
-
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?
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 ?
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 https://www.yoursite.com/archives/category3/.
The codex is really helpful here.
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!
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.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 ??
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.
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.
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.
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.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.
[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: https://www.sportsklubben.no/alag
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?
“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.
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?
- The topic ‘hide an post on main page’ is closed to new replies.