Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
Puchar WPB
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

Jak wyświetlać opisy kategorii w WordPress

Uwaga redakcyjna: Otrzymujemy prowizję z linków partnerskich na WPBeginner. Prowizje nie mają wpływu na opinie i oceny naszych redaktorów. Dowiedz się więcej o Proces redakcyjny.

Czy chcesz wyświetlać opisy kategorii na twojej witrynie WordPress?

Kategorie umożliwiają łatwe sortowanie treści w twojej witrynie internetowej. Pomagają również użytkownikom łatwo znaleźć treść i są dobre dla SEO.

W tym artykule pokażemy, jak łatwo dodać opisy do twoich kategorii w WordPress.

How to Display Category Descriptions in WordPress

Dlaczego warto wyświetlać opisy kategorii w WordPress?

Jeśli stworzyłeś witrynę internetową WordPress, to prawdopodobnie korzystasz już z kategorii i tagów. Być może jednak nie wykorzystujesz ich pełnego potencjału.

Kategorie i tagi umożliwiają łatwe sortowanie twojej treści na różne tematy. Prawidłowo używane kategorie i tagi mogą być również bardzo pomocne w poprawie SEO twojego WordPressa.

WordPress umożliwia dodawanie opisów do twoich kategorii. Mogłeś tego nie powiadomić, jeśli tworzysz kategorie podczas pisania wpisu, ponieważ ta metoda nie pozwala na dodanie opisu.

Mając to na uwadze, przyjrzyjmy się, jak łatwo dodać opisy do twoich kategorii w WordPress.

Dodawanie opisów kategorii w WordPress

Najpierw należy przejść do strony Wpisy ” Kategorie. Jeśli tworzysz nową kategorię, możesz po prostu wpisz jej nazwę i opis, a następnie kliknij przycisk „Utwórz nową kategorię”.

The Posts»Categories Page

Jeśli chcesz dodać opis do istniejącej kategorii, kliknij odnośnik „Edytuj” znajdujący się pod tą kategorią.

Spowoduje to przejście do ekranu edycji kategorii, na którym można dodać opis twojej kategorii.

Add a Description to a Category

Nie zapomnij kliknąć przycisku „Aktualizuj”, aby zapisać twoje zmiany.

Powtórz ten proces, aby dodać opisy do wszystkich twoich kategorii. Możesz użyć tej samej metody, aby dodać opisy również do tagów.

Wyświetlanie opisu kategorii na stronach archiwum kategorii

Większość motywów WordPress automatycznie wyświetla opis kategorii na stronach archiwum kategorii.

Display Category Descriptions on Category Archive Pages

Jeśli jednak twój motyw nie wyświetla opisów kategorii na stronach archiwum, będziesz musiał zmodyfikować swój motyw. Najbezpieczniejszym sposobem jest utworzenie motywu potomnego.

Aby uzyskać więcej informacji, zapoznaj się z naszym przewodnikiem dla początkujących na temat tworzenia motywu potomnego.

Następnie należy skopiować plik z motywu nadrzędnego do motywu potomnego. Możesz użyć klienta FTP lub menedżera plików cPanel oferowanego przez twoją firmę hostingową WordPress.

Będziesz musiał przejść do katalogu /wp-content/themes/parent-theme/ twojej witryny internetowej i znaleźć plik category.php. Jeśli twój plik nie zawiera tego pliku, będziesz musiał zamiast tego znaleźć archive.php.

Find category.php or archive.php Using FTP Software

Następnie należy skopiować plik do katalogu twojego motywu potomnego.

Następnie należy edytować plik, a następnie dodać ten fragment kodu w miejscu, w którym ma być wyświetlany opis kategorii:

<?php
the_archive_description( '<div class="taxonomy-description">', '</div>' );
?>

Zazwyczaj będzie to zaraz po sekcji zawierającej the_archive_title. Nie zapomnij zapisać pliku po wklejeniu kodu.

Paste the Code Snippet

Twoje strony archiwum kategorii będą teraz wyświetlać opisy kategorii.

Oto przykład z naszej witryny demonstracyjnej. Motyw Twenty Nineteen domyślnie nie wyświetla opisów kategorii, ale po dodaniu fragmentu kodu do motywu potomnego widać, że opis kategorii jest teraz wyświetlany.

Preview of Category Description

Wyświetlanie opisu kategorii w motywie WordPress

Jeśli czujesz się komfortowo używając kodu na twojej witrynie internetowej WordPress, możesz użyć tych fragmentów kodu do wyświetlania opisów kategorii w innych miejscach na twojej witrynie.

Wyświetlanie pojedynczego opisu kategorii na twojej witrynie internetowej

Jeśli chcesz wyświetlić opis kategorii w innych częściach twojej witryny internetowej, musisz użyć tagu szablonu category_description:

<?php echo category_description(3); ?>

Musisz zastąpić 3 identyfikatorem kategorii, której chcesz użyć.

Wyświetlanie opisów kategorii w każdym wpisie

Jeśli chcesz wyświetlać opis kategorii wewnątrz pojedynczych wpisów, możesz dodać fragment kodu np. do szablonu single.php lub footer.php.

Jeśli korzystasz z motywu potomnego, musisz najpierw skopiować szablon z motywu nadrzędnego do katalogu motywu potomnego.

Następnie należy dodać ten kod:

$catID = get_the_category();
echo category_description( $catID[0] );

Ten kod po prostu pobiera wszystkie kategorie dla obecnego, aktualnego wpisu, a następnie wyświetla opis pierwszej kategorii.

Lista wszystkich kategorii i opisów

Jeśli chcesz wyświetlić wszystkie swoje kategorie WordPress z opisem w formacie listy, możesz dodać ten kod do pliku functions.php twojego motywu lub wstawić fragment kodu za pomocą wtyczki WPCode (zalecane).

Aby uzyskać szczegółowe informacje, zapoznaj się z naszym przewodnikiem na temat dodawania własnego kodu w WordPress.

function wpb_catlist_desc() {
$string = '<ul>';
$catlist = get_terms( 'category' );
if ( ! empty( $catlist ) ) {
  foreach ( $catlist as $key => $item ) {
    $string .= '<li>'. $item->name . '<br />';
    $string .= '<em>'. $item->description . '</em> </li>';
  }
}
$string .= '</ul>';

return $string;
}
add_shortcode('wpb_categories', 'wpb_catlist_desc');

Ten kod tworzy krótki kod, który wyświetla wszystkie twoje kategorie i ich opisy na zwykłej liście.

Możesz teraz używać [wpb_categories] w twoich wpisach i stronach. Aby użyć tego krótkiego kodu wewnątrz widżetu tekstowego, musisz włączyć krótkie kody dla widżetów.

List WordPress categories with description

Bonus: Dodanie meta opisu kategorii w celu poprawy SEO

Domyślnie WordPress nie doda twojego opisu kategorii w meta tagach.

Dlatego ważne jest, abyś używał wtyczki WordPress SEO, takiej jak All in One SEO for WordPress, aby dodawać meta opisy kategorii w celu zwiększenia twojego SEO.

Adding a meta description for your category in All in One SEO

Przewodniki ekspertów po kategoriach WordPress

Teraz, gdy już wiesz, jak wyświetlać opisy kategorii, możesz zapoznać się z innymi przewodnikami związanymi z kategoriami WordPress:

Mamy nadzieję, że ten poradnik pomógł ci dowiedzieć się, jak wyświetlać opisy kategorii w WordPress. Możesz również zapoznać się z naszym przewodnikiem na temat przenoszenia WordPressa z HTTP na HTTPS lub naszymi eksperckimi typami wtyczek, które musisz mieć, aby rozwinąć swoją witrynę.

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.

Ujawnienie: Nasze treści są wspierane przez czytelników. Oznacza to, że jeśli klikniesz na niektóre z naszych linków, możemy otrzymać prowizję. Zobacz jak WPBeginner jest finansowany, dlaczego to ma znaczenie i jak możesz nas wspierać. Oto nasz proces redakcyjny.

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

Najlepszy zestaw narzędzi WordPress

Uzyskaj BEZPŁATNY dostęp do naszego zestawu narzędzi - zbiór produktów i zasobów związanych z WordPressem, które każdy profesjonalista powinien mieć!

Reader Interactions

27 komentarzyZostaw odpowiedź

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

    • WPBeginner Support says

      To prevent that you would either need to create a site specific plugin or a child theme

      Administrator

  2. Mirela says

    Hi. How do you make the description show only on the first page of the category? I want to avoid duplicate content :(

    • WPBeginner Support says

      Your SEO plugin should prevent duplicate content if you mean the description on the category archive

      Administrator

    • WPBeginner Support says

      No, this would be for standard WordPress categories and not WooCommerce categories

      Administrator

  3. Tiffany says

    So I created a category for slow cooker recipes. I titled it it „healthy slow cooler recipes”. It displays properly in the drop down menu and on the back end. But when I look at the category results page from the front end, it has extra words at the front of the title that I can’t find anywhere and I did not add them. I need to delete them but I’m not sure where this is pulling from. Any ideas?

    • WPBeginner Support says

      Your theme would likely be what’s adding it. If you reach out to your theme’s support they should be able to assist you.

      Administrator

  4. Ola says

    God bless you real good. Please, how do I make the categories clickable? so that when someone clicks on each category, it will take them to the Archive list

  5. Anthony says

    Wondering if it’s possible to do this with custom post types. I have a recipe website and would love to add the descriptions to help with SEO.

    Thanks.

    • WPBeginner Support says

      As long as your custom post type accepts categories it should be able to display the same way.

      Administrator

  6. Sandra says

    Hi,
    Is there a way to hide the description of the categories? I am looking for the opposite of this post (Hide Category Descriptions) but can’t seem to find anything :(

    My previous theme didn’t display category descriptions, but I updated today to wpocean and this new theme does display the text, I don’t like it. I feel that users will get lost or won’t scroll down to read the posts :/

    Is there a code to fix it?

    • WPBeginner Support says

      You would want to reach out to the support for your current theme first to see if there is an option to do so built-in with the theme or a recommended method to remove the description.

      Administrator

  7. Mads Grønlund says

    EDIT: I am now subscriting to replies. You can delete my other reply. :-)

    Hey! Great post, although I would like to ask, is there a way to move the category description to the bottom of the page? In case I want say a 2.000 words description for the SEO-value but I don’t want it to block all the actual posts in that category.

    Thanks in advance!

    • WPBeginner Support says

      Hi Mads Grønlund,

      Yes, you can do that. For that you will need to edit your theme template files like category.php. Look for the code responsible for displaying description and move it down towards the end of the loop. You may run across some issues, so it would be best to backup your original template files first.

      Administrator

  8. Dejan says

    Hello everyone,

    This is very useful post and I was cracking my head why the category description wasn’t being displayed in my theme, and following this tutorial it occured to me that my theme didn’t even have the category.php or archive.php files!
    In such cases you need to edit the index.php file with the code provided in this tutorial. It worked like a charm for me :)

    • D says

      I don’t have category or archive in my theme either. Tried posting code in index.php but didn’t work (and i have no clue what I’m doing to post the code there) any way you can elaborate on the steps a little more?

  9. Madison Woods says

    Is there a way to make the category description only show up on the first page of category archives? Isn’t it 'duplicate content’ if it appears on every page of that category’s posts? Some of my categories contain a large amount of posts so there might be 4 or 5 pages of 'older posts’ in that category. Each one of those pages of posts shows the same description. Thanks for any tips!

  10. Naomi says

    Thanks so much for this tip – it worked absolutely perfectly and it saved me a lot of potential headaches.

    My category description is showing up as planned, just where I wanted it to :)

  11. Beth says

    If my category is a subcategory I notice there are two description boxes to fill out. Only the bottom one will automatically show up on my subcategory page. Should I fill out both description boxes? Should they be the same?

Zostaw odpowiedź

Dziękujemy za pozostawienie komentarza. Pamiętaj, że wszystkie komentarze są moderowane zgodnie z naszymi polityka komentarzy, a Twój adres e-mail NIE zostanie opublikowany. NIE używaj słów kluczowych w polu nazwy. Przeprowadźmy osobistą i konstruktywną rozmowę.