I WordPress kan dina inlägg organiseras i olika kategorier och taggar. Du kan till och med skapa underkategorier för ytterligare organisation.
Genom att använda kategorier och underkategorier kan du hjälpa dina läsare att hitta det innehåll de är mest intresserade av och förbättra din webbplats SEO-rankning.
Under de senaste 16 åren har vi på ett effektivt sätt organiserat våra inlägg i kategorier och underkategorier på alla våra webbplatser för att förbättra navigeringen på webbplatsen för våra läsare. Detta har förbättrat vår tillgänglighet och bidragit till högre sökmotorrankning genom att göra vårt innehåll mer användarvänligt.
I den här artikeln visar vi dig hur du enkelt kan add to kategorier och underkategorier i WordPress, steg för steg.
Förstå kategorierna Parent och Child i WordPress
Kategorier är ett kraftfullt verktyg. De är ej bara ett sätt att sortera ditt content. De hjälper dig också att utveckla en korrekt struktur på din site som är meningsfull och semantisk. Detta är bra för din sökmotorsoptimering i WordPress.
Note: Om du inte är clear med skillnaden mellan kategorier och taggar, ta en titt på vår guide om kategorier vs taggar. Där förklarar vi varför kategorier och taggar är olika och hur du använder dem korrekt.
Nu kanske du undrar, varför och när skulle någon behöva använda underkategorier (underkategorier) på sin WordPress-webbplats?
Låt oss säga att du skapar en blogg för olika resmål runt om i världen. Du kanske vill att användarna ska kunna hitta artiklar efter både land och stad.
You kanske till exempel har en artikel om de bästa vattenparkerna i USA. Det skulle vara vettigt att använda ”USA” som kategori för den posten.
Men du kanske också har artiklar om de bästa ställena att äta i New York City, Los Angeles, Chicago och mer. Det är här du kan använda child- eller underkategorier. Då kan ”United States” bli en parent category och städerna kan bli child categories.
Ett post som är publicerat under en child category behöver inte också vara publicerat under parent category. I vårt exempel kunde vi ha låtit ”United States” vara avmarkerat och bara lagt posten i kategorin ”New York City”.
Om you filar ett post under child category men ej under parent category, så kommer your post endast att visas på archive pages för child category.
Med detta sagt, låt oss ta en titt på hur man add to både vanliga kategorier och child kategorier i WordPress.
Lägga till en Category i WordPress
Du kan enkelt add new kategorier i WordPress när du skriver en post.
Först, om sidebaren inte visas när du redigerar ett post, måste du klicka på kugghjulsikonen högst upp till höger.
Öppna sedan tabben Categories i panelen Block på höger sida.
Du kommer att se olika kategorier som du redan har skapat.
Men för att skapa en ny kategori kan du helt enkelt klicka på länken ”Add New Category”.
När du klickar på länken visas två nya boxar där du kan add to din Category.
För en vanlig kategori behöver du inte välja något i dropdown-rutan Parent Category.
När du har skrivit in namnet på din kategori klickar du bara på knappen ”Add New Category”.
Boxen för den kategorin kommer då automatiskt att kontrolleras för din aktuella post. Du kan avmarkera den om du vill.
Du kan också add new en kategori utan att edit en post.
Gå bara till Posts ” Categories och lägg till din nya kategori. Detta är praktiskt om du vill skapa alla dina kategorier innan du lägger till content.
Med den här metoden kan du också editera sluggen (URL) för dina kategorier. Du kan även delete och byta namn på kategorier och ge dem en description. Se hur du add to sökmotorsoptimeringar och descriptions i WordPress.
Lägga till en Child Category (underkategori) i WordPress
Du kan lägga till och edit child kategorier på exakt samma sätt som du lade till dina parent kategorier.
När du redigerar ett post öppnar du panelen för inställningar och rullar ner till tabben Categories.
Klicka sedan på alternativet ”Add New Category” och skriv in namnet på din child-kategori. Välj sedan den Category som du vill använda som parent i dropdown-listan.
På samma sätt kan du också gå till Posts ” Categories för att add to child categories.
Skriv bara in namnet på din child category och välj parent category från dropdown-menyn.
Your child categories kan också ha sina egna child categories om you vill.
Vi kan till exempel bestämma oss för att utveckla en kategoristruktur som används för att gruppera flera olika typer av content, som vi gillar det här:
Här är News en kategori med Announcements som child-kategorier.
Kategorier på samma nivå inom en kategori med en parent anropas ibland som ”syskonkategorier”. Till exempel är Announcements och Sökmotorsoptimering kategorier här.
Kategorier kan bara ha en parent. You can’t add to one sub-category under two different parent categories.
Sökmotorsoptimering – fördelar med kategoribaserad site-struktur
Dina kategoriers URL:er kommer att se ut ungefär så här:
https://example.com/category/united-states/new-york-city/
Detta är meningsfullt och hjälper search engines och visitors att förstå vad din page handlar om. Du får också en chans att add to keywords till din URL. Keywords hjälper människor att hitta content på search engines.
WordPress tillåter dig också att enkelt ändra prefixet /category/ i dina kategoriers URL:er. Du kan till och med ta bort det helt om du vill.
Gå bara till Settings ” Permalinks page från WordPress adminpanel och rulla ner till ”Category base” section.
Här kan du enter det prefix du gillar att använda och klicka på knappen ”Save Changes” för att store dina ändringar.
Prefixet ”category” i dina kategoriers URL:er addar inte till någon fördel för din sökmotorsoptimering.
Det är därför som vissa webbplatsägare föredrar att ta bort ordet ”kategori” från URL:erna till sidorna i deras WordPress-kategoriarkiv. Du kan enkelt göra detta genom att använda All in One SEO plugin, så att dina kategori-URL:er ser ut så här:
http://example.com/united-states/new-york-city/
Gå bara till menyn Search Appearance för AIOSEO och välj sedan tabben Taxonomies. Under de avancerade inställningarna för Categories ser du alternativet att ta bort kategoribasprefixet.
Alternativt kan du också använda FV Top Level Categories plugin. Installera bara pluginet och det kommer att ta bort ordet ”kategori” från dina kategori archive pages URL:er.
Viktigt: Om du bestämmer dig för att ändra kategoribasen på en befintlig WordPress-webbplats måste du ställa in redirects för att undvika 404 error för besökare i search engine. För mer detaljerade instruktioner, följ vår guide om hur du ändrar prefixet för kategoribasen i WordPress.
Så här visar du kategorier och child-kategorier i sidebar i WordPress
Du kan add a widget block to your WordPress sidebar or footer to show a list of categories. I din WordPress dashboard, gå till Appearance ” Widgetar.
Om du inte har ändrat dina widgetar från dem som WordPress placerar där som standard, bör du se widgetblocket Categories redan på plats. Om ej, kan du click the ”+” button and add a ”Category” block to your widget area.
Som standard visar widgeten alla dina kategorier i en platt lista, i alfabetisk order.
Här är en preview av hur de såg ut på vår test website:
Tips och råd: Kategorierna visas bara i listan om du har tilldelat dem minst 1 publicerad post.
Du kan ändra det så att child-kategorierna (underkategorier) visas under sina parent-kategorier om du vill. Aktivera helt enkelt alternativet ”Visa hierarki” i widgetens inställningar så här. Glöm inte att clicka på knappen ”Update”.
På din site bör du nu se dina parent categories med child categories inbäddade under dem.
Tips: Om ändringarna i sidebar inte visas kan du behöva cleara din WordPress-cache.
Notis: Förutom standard widget block för kategorier, kan du också skapa cust omize kategori menylänkar med hjälp av WordPress navigation menu. Efter det kan du add to den menyn till din header-meny, sidebar, footer, eller andra menu locations.
Bonus: Display Subcategories on Category Pages in WordPress (Visa underkategorier på Category Pages i WordPress)
När du har lagt till underkategorier på din website kan du visa dem på dina category pages. Det gör det lättare för användarna att navigera i ditt content och kan öka trafiken.
För att visa underkategorier måste du add to följande custom code till din category.php-fil. Du hittar den här foldern i filerna för ditt theme.
<?php
if (is_category()) {
$this_category = get_category($cat);
}
?>
<?php
if($this_category->category_parent)
$this_category = wp_list_categories('orderby=id&show_count=0
&title_li=&use_desc_for_title=1&child_of='.$this_category->category_parent.
"&echo=0"); else
$this_category = wp_list_categories('orderby=id&depth=1&show_count=0
&title_li=&use_desc_for_title=1&child_of='.$this_category->cat_ID.
"&echo=0");
if ($this_category) { ?>
<ul>
<?php echo $this_category; ?>
</ul>
<?php } ?>
När du har gjort det, besök bara någon kategori page på din webbplats där du kommer att notera en lista över dess underkategorier som användare kan bläddra i.
För detaljer, se vår tutorial om hur man visar underkategorier på category pages i WordPress.
Vi hoppas att den här poradniken hjälpte dig att lära dig hur du lägger till kategorier och underkategorier i WordPress. Du kanske också vill ta en titt på vår artikel om hur du skapar anpassade taxonomier i WordPress och vår przewodnik om hur du lägger till quicktags i WordPress kommentarformulär.
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.
Atul Tanna
I have a Buying Guide, Review, and Categories and Under Categories I have several sub categories
When I Review Amazon Products I would like them to appear under Reviews and at te same time time I would like them to appear in one of the sub categories How do I get started and what do I do
Thanks
WPBeginner Support
Unless your theme specifically hides them, your category pages should include any subcategories in the list of posts. You can create the category pages by linking to your category in your menu and our guide below should help create your menu!
https://www.wpbeginner.com/beginners-guide/how-to-add-navigation-menu-in-wordpress-beginners-guide/
Administratör
Alaba
Hi, my site has some categories that don’t have any parent category. However, these were created a long time ago. Can I just assign them one?
WPBeginner Support
You can but if you have any posts under the categories, be sure to redirect any posts that had their URLs changed
Administratör
Ayo
Hi, How can I have a parent category that covers all the posts of its subcategories like the one on this web (https://www.wpbeginner.com/blog/)?
WPBeginner Support
That would be your posts/blog page that you can set under Settings>Reading
Administratör
Imran khan
When using child categories, should I check the parent category also checked, or keep it unchecked?
WPBeginner Support
If you mean when adding a post to the category, you would only need to check the child category
Administratör
Imran khan
I have my permalink structure set to “/%category%/%postname%/” and I want to show the parent category in my URL.
1. If I checked the child category my post URL’s are showing: “www.my-site.com/parent-cat/child-cat/post-name/”
2. If I checked both child and parent categories, my post URL’s are showing: “www.my-site.com/parent-cat/post-name/” that I want. So now should I check the parent category also checked, or keep it unchecked? If i checked both then it would not be an issue to have duplicate content that will negatively affect on SEO.
WPBeginner Support
Your URLs are like that as your parent category would be used first. It should not affect your SEO but you can use both categories if you wanted. Otherwise, we would recommend taking a look at the recommendations from our article below:
https://www.wpbeginner.com/wp-tutorials/how-to-change-the-category-base-prefix-in-wordpress/
Terry
Can subcategories be used for products?
WPBeginner Support
Yes, as long as your eCommerce plugin allows.
Administratör
Sade
Hi,
I have made my catergory showing at the top a drop down, but when I put category in my primary sidebar when I click it says ’select category’ and doesn’t show my sub categories. How do I fix this?
Thanks
WPBeginner Support
You would normally need to manually add subcategories if we’re understanding what you’d want correctly.
Administratör
Ebi
Hi
Can I generate multiple articles for the main category without selecting a subcategory for it (with a few subcategories), is this SEO desirable?
WPBeginner Support
You can have multiple posts in one category if you wanted and not use subcategories, it would depend on the overall organization of your site for how useful it would be and if it would have any SEO effect.
Administratör
usman
hay i need to know how i display sub-category show in menu when i add new show auto into the menu
WPBeginner Support
For customizing your menu, you would want to take a look at our guide below:
https://www.wpbeginner.com/beginners-guide/how-to-add-navigation-menu-in-wordpress-beginners-guide/
Administratör
Candy
I have six categories on my homepage. When you click the image on the homepage, it takes you to that category page. I am having an issue with blog posts. How do I get the blog post to automatically appear on the correct category page? I’m been doing this manually and I know there has to be another way. Thanks in advance!
WPBeginner Support
You should be able to link to the category page for WordPress to automatically list the posts in a category. You can get the link to your category page by adding a category to your menu. You should not be manually creating your category pages.
Administratör
Stef
You mentioned if you don’t attach the item to the parent and only the child that it wouldn’t show up in the parent. This is incase you don’t want duplicate content.
If left attached to both would this create an SEO issue of having duplicate content then? I know Google frowns upon duplicate content, but you didn’t say.
Thanks in advance.
WPBeginner Support
It should not cause a duplicate content issue either way.
Administratör
Muhammad Salman
Good. It helped me a lot thanks wpbeginner
WPBeginner Support
You’re welcome, glad our article was helpful
Administratör
Julie
Thanks,
I was told I was creating my categories incorrectly as they had the word ‘category’ in the URL. I read several posts on how to create categories and yours was the only one explaining this.
That said, how bad is it to have this? I hate to add in yet another plugin. It really doesn’t bother me…unless it should for some reason.
Julie
WPBeginner Support
There is a large amount of personal preference as search engines don’t specify their preference other than being easy for users to understand. You can always update your category names if you wanted but it is not a hard requirement. For adding more plugins, for the most part, you shouldn’t worry. For our guide on plugins you would want to take a look at our article here:
https://www.wpbeginner.com/opinion/how-many-wordpress-plugins-should-you-install-on-your-site/
Administratör
Steve
Is there a way to filter the categories? Id like to show the categories related only to this page topic.
WPBeginner Support
For what it sounds like you’re wanting, you may want to take a look at our guide on adding conditional logic to menus: https://www.wpbeginner.com/plugins/how-to-add-conditional-logic-to-menus-in-wordpress/
Administratör
Anna Tang
Thank you for the tutorial. It was clearly written and I solved my category/subcategory issues within 5 minutes.
Best,
Anna
WPBeginner Support
Glad our article could help
Administratör
Kelly Quek
Hi I need help.. I have accidentally click on make a default.. How to undefault it back?
WPBeginner Support
You can change which category is the default under Settings>Writing but you must have at least one default category
Administratör
Michael Taylor
Is it possible to create a hierarchy with lets say parent, child, grandchild , and great grandchild? in other words…
United States > California > San Francisco > Hotels
United States > Nevada > Las Vegas > Hotels
United States > New York > New York City > Hotels
Canada > British Columbia > Vancouver > Resturantrs
WPBeginner Support
Yes you can have multiple subcategories beneath a subcategory if you wanted
Administratör
dinesh
How can I represent woocommerce categories, subcategories, and products in the form:
1) A form consists of 3 fields categories, subcategories, and products
2)If we select one category the related subcategories should be displayed in subcategories feild.
3)Select Subcategory , such that the product should be displayed by related categories and subcategories
4) And if we submit the form It should redirect to checkout page
WPBeginner Support
Rather than in a form, you may want to take a look at the plugin in our article: https://www.wpbeginner.com/plugins/how-to-let-users-filter-posts-and-pages-in-wordpress/
Administratör
sera
Hi
i have a problem
i want to associate one subcategory to a few parents
for example:
outdoor > panel
indoor > panel
outdoor & indoor is parents and panel is a child
can you help me please??
thaks a lot
Usama Ahmed
That is the most basic example of many to many relationship inside categories. One Category with multiple parents.
Unfortunately WordPress is a pile of garbage and till this date this feature is not available.
Sunshine Vaughn
I don’t want all of my posts to show when i click on the parent. How do i go about fixing this?
I only want to see the posts directly placed in each category and then list out each sub category just like you would in using Windows Explorer.
Thank you,
Sunshine
Mike
I’m helping a friend switch update their website, and upon investigation they built it mainly from categories and sub-categories, with only four (unfinished and unlinked) pages and the reading setting as show recent posts, instead of having a static homepage. The main menu displays categories with sub categories highlighted underneath.
My question is, what’s the best way to update the site, by adding a static homepage and other primary pages for the posts to be listed with without messing with the overall organization of the content?
Denis
How can we add a third level of subcategory in Woocommerce ?
Bhat Muzamil
It was very helpfull to me thanks for such a awesome article
Bel
Hello, awesome site. Thank you you have helped me to build my website.
I have question hoping you can help – is there an plugin to place small images left side of post summaries on landing page.? I have looked and searched and even paid for a plugin that did not operate. Any help would be great.
Steven Denger
Very helpful like all your tutorials are. I always come here to learn the best practices as well as great plugin resources. Thanks for this tutorial.
Stefan
So… what is a sub-category good for?
I can just have ”United States” and ”New York” — both as categories, and simply drag ”New York” under ”United States”. They’ll be displayed the same, as category / subcategory, only that they’re both categories.
I can choose if an article goes to both, or just one of the categories.
So, what is the use of having a subcategory?
WPBeginner Support
Hey Stefan,
Subcategories allow you to add subtopics to a category. An article, filed in a sub-category is also displayed in the parent category. However, an article filed in a sibling category will not be displayed on other sub-categories that are also part of the same parent category.
Administratör
Vijeesh Vijay
Duplicate content is the major issue when assigning posts to both parent categories and child categories. For example, I want the same post to show up under ”united states” parent category and ”New York” child category. However I need more than 1 post in each child category to avoid duplicate content.
The problem occurs when you have a menu or website navigation made of categories. You have to wait until the blog is big enough to have a few articles in each sub categories to make a proper menu. Is there a way around this ?
Anja
Hi VIJEESH,
It shouldn’t be a problem. The url of the page/post remains the same, it is mentioned in the category page and Google recognizes this, their bots are really intelligent To avoid it even better I suggest you install YOAST SEO, a free plugin, which is great for your SEO and they offer the option to avoid duplicate content from categories as well in the settings menu.
Hope this helps!
Anja
rose
hi guys!
I’ve been working on my website and for days I’m trying to figure out on how to work the sub menus on my two blog categories namely lifestyle and tv series- the 1st submenu is working out fine but the 2nd level up to fourth level- I can’t click it al all.
i’ve tried plugins and all
is there anyone can help me with this please? Thanks so much
sincerely,
rose
Jill
Great article. This was a HUGE help!
Question:
You explained how to get the child categories to show on the blog sidebar but how do I get them to show on the top bar as drop downs?
vivek
To do this go to Posts -> All Posts. Next, select the posts you want to add to a category, click on the Bulk Actions tab, select Edit and finally press the Apply button. Once you do that, you will few options you can adjust for those posts. One of them is the Categories section.
Harish Negi
I am using category and subcategory, but they are not reflecting in my URL. is there any reason for that in wordpress. Please answer..
evan
I would like my category pages to show the sub-category PAGES that belong to that post. Currently, my category pages are show the subcategory POSTS.
How do I fix this?
Alex
Great read, thanks!
I am creating a website with the exact same example you gave. I am wondering if it’s better to have the permalink structure set to:
1. /continent/country/destination/%postname% or to
2. /%postname%
I am not sure if the first option is better, since it is becoming quite long.
Thank you for your help!
Nicole
What if you want the category’s to be going across the top of the page and not on the side?
Mikey
Thanks for the help!
Urooj
Thank you for this post. I understand the category and the sub categories you explained. There si something I want for the my website. I make a category for a course with the course name now for the sub-categories, say, I want books, audios, videos and flashcards also I want a page which shows all the books from all the categories I have on a single page. Same for the audios, videos and flashcards. Is that possible without duplication?
Jason
Is it possible to have multiple subcategories with the same name? For example, to categorize counties in the United States as State -> County. I would like Mississippi -> Jackson but also Alabama -> Jackson. Jackson county exists in both states, but should be entirely unrelated. Any way to accomplish this?
Rolfa Stol
I add category per easy instructions above ( visit POSTS–add new category..) and the added show up to the right, correctly as far as i can see, but not on main page under categories. Impossible to get it there, only the default ”uncategorixed” show up there. Really strange, as i need to use Kudani and make a post on distance, but it also seems to think i have no category…..
WPBeginner Support
Simply creating a category is not enough. You may also need to assign atleast one post to that category. By default, WordPress sometimes does not display empty categories.
Administratör
Anca
Great info! Thank you very much!! I finally managed to create a sub-category
WPBeginner Support
Glad you found it helpful.
Administratör
Suzy
Dear staff,
What if I want to display my 2 subcategories on their parent category page?
I know that there is some sort of code, but where exactly should I paste this code, in the functions.php?
Thank you
evan
I have the same question. Please let me know if you found an answer
Ian Anderson
Hiya, thanks for the tutorial.
Any tips where categories overlap? For example my DIY site often features stuff made from wood but also repairing or maintaining stuff made from wood. Do I categorize ’wood’ or ’repair’ / ’maintain’.
Plus different materials (metal/tile/fabric etc) so I’m really struggling to know what to put first, material or action?! Either way it looks like I’m going to have duplicate subcategories…
Sometimes wish I had a needle narrow skillset lol!
Kaye
Is there a limit on categories? I currently have 10 displayed but have 12 listed so two is not showing up. Is there a way to add more so that the last two will show up. When going to my site live I see the two space on the third row but they are not showing up. What am I doing wrong
WPBeginner Support
By default, WordPress does not show empty categories in the category lists. Please see our guide on how to show empty categories in WordPress widgets
Administratör
Elliot
Is there a limit to the amount of categories enabled on word press?
I have a large amount of subcategories and wordpress won’t allow me to add anymore, it seems to just boot an old category out in order to make space for the new one?
Can anybody help?
Rahul Choudhary
Hi Syed
Thanks for this article. The example you have given here is exactly the same scenario i am dealing with. Now here is situation I have Categories
Parent Category : Australia
Child Category: NSW
Child Child Category : Sydney
I also have three more Parent categories at same level as Australia
Apple
Microsoft
Other
Now when I create a post I assign Parent & child categories because I am using ajax search to filter the result on hierarchy based. I also select one of those parent categories as well : Apple, Microsoft or Other.
Now I have a search box where I sort the result based on country city or town. I would like to have a one more search box where I could sort based on Apple, Microsoft or others where once I select apple then it should display Australia -> NSW -> Sydney.
Its like country (parent) category will be a child category in this search.
Is this possible?
Thanks
Rahul
WPBeginner Support
Take a look at SearchWP plugin. It has a taxonomy filter that might work for your scenario.
Administratör
francis okoye
Thanks for d tutorials was really helpful. How can I make my subcategory to appear when the mouse is hovered on the category. I don’t want the subcategory to show beneath the category. I want it to show on hovering the category…. Any help please
Rahul
Hi
I am having real problem sorthing this category issue. I want to display hotels & Car Rental in various countries so:
Country
-> US -> Alabama -> Montgomery
-> Australia -> NSW -> Sydney
Country is the ultimate parent category I would like to have.
Then I would like to display either all the hotels or Car Rental in that particular city.
So basically countries will have both hotels and car rentals but I would like to display hotels only in Sydney if user decided to display hotels only or car rental.
Help Needed.
Cheers
claude apetse
hello admin , i found very interesting post in your tag. but in my , the first day after hosting the site (wordpress) i added some category but after a while ( some days after) i could no longer add new category . it is adding of course in the category form when i fill it but not showing in the homepage of the site
WPBeginner Support
A category will not appear on your site until you publish a post in that category.
Administratör
Chris
Are the categories you mention in this post only applicable to POSTS, or can categories be added for PAGES as well? I don’t see an option for creating a category for PAGES.
WPBeginner Support
By default pages cannot be categorized. See our guide on the difference between posts and pages. However, you can use a plugin to make categories and tags available for pages as well.
Administratör
Ruby
I really needed this tutorial! Thank you so much for making it so easy to understand.
sandeep Kumar Dan
Hi, Sayed
Great article , its really helpful , I was doing an product listing project . Where i was need many category subcategory option , finally I did it with this tutorial. Thanks a lot
sue
I have added another sub category to an existing list and it does not show up on the blog page?
TIA