{"id":74,"date":"2025-02-22T22:48:20","date_gmt":"2025-02-22T22:48:20","guid":{"rendered":"https:\/\/notes.zj1963.com\/?p=74"},"modified":"2025-02-22T22:48:20","modified_gmt":"2025-02-22T22:48:20","slug":"group-pages-with-categories","status":"publish","type":"post","link":"https:\/\/notes.zj1963.com\/?p=74","title":{"rendered":"Group Pages with Categories"},"content":{"rendered":"\n<p><strong>Can You Group Pages by Category in WordPress?<\/strong><\/p>\n\n\n\n<p>By default,&nbsp;<strong>WordPress does not support categories for pages<\/strong>&nbsp;(only for posts). However, you can still group pages using categories by using&nbsp;<strong>plugins or custom code<\/strong>.<\/p>\n\n\n\n<p><strong>1\ufe0f\u20e3 Using a Plugin (Easy Method)<\/strong><\/p>\n\n\n\n<p>The easiest way to add&nbsp;<strong>categories to pages<\/strong>&nbsp;is by using a plugin.<\/p>\n\n\n\n<p><strong>\ud83d\udccc Recommended Plugin:&nbsp;<\/strong><a href=\"https:\/\/wordpress.org\/plugins\/pages-with-category-and-tag\/\"><strong>Pages with Category and Tag<\/strong><\/a><\/p>\n\n\n\n<p>\ud83d\udd39&nbsp;<strong>Features:<\/strong><\/p>\n\n\n\n<p>\u2705 Adds category and tag support to pages<\/p>\n\n\n\n<p>\u2705 Lets you filter and display pages by category<\/p>\n\n\n\n<p>\u2705 Works with WordPress menus and widgets<\/p>\n\n\n\n<p><strong>\ud83d\udd39 How to Use:<\/strong><\/p>\n\n\n\n<p>1.&nbsp;Install &amp; activate the&nbsp;<strong>\u201cPages with Category and Tag\u201d<\/strong>&nbsp;plugin.<\/p>\n\n\n\n<p>2.&nbsp;Go to&nbsp;<strong>Pages \u2192 Categories<\/strong>&nbsp;(just like posts).<\/p>\n\n\n\n<p>3.&nbsp;Assign categories to pages.<\/p>\n\n\n\n<p>4.&nbsp;Use the following shortcode to display grouped pages:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;query_pages category_name=\"your-category\"]<\/code><\/pre>\n\n\n\n<p>(Replace&nbsp;&#8220;your-category&#8221;&nbsp;with the actual category name.)<\/p>\n\n\n\n<p><strong>2\ufe0f\u20e3 Adding Categories to Pages via Custom Code (Advanced)<\/strong><\/p>\n\n\n\n<p>If you don\u2019t want a plugin, you can manually enable&nbsp;<strong>categories for pages<\/strong>.<\/p>\n\n\n\n<p><strong>\ud83d\udd39 Step 1: Add This Code to Your Theme\u2019s functions.php File<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function add_categories_to_pages() {\n    register_taxonomy_for_object_type('category', 'page');\n}\nadd_action('init', 'add_categories_to_pages');<\/code><\/pre>\n\n\n\n<p>\ud83d\udccc This will&nbsp;<strong>enable categories for pages<\/strong>, allowing you to group them.<\/p>\n\n\n\n<p><strong>\ud83d\udd39 Step 2: Display Pages by Category<\/strong><\/p>\n\n\n\n<p>To list pages by category in a template, use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n$pages = get_posts(array(\n    'post_type' =&gt; 'page',\n    'category_name' =&gt; 'your-category',\n    'posts_per_page' =&gt; -1\n));\n\nforeach ($pages as $page) {\n    echo '&lt;a href=\"' . get_permalink($page-&gt;ID) . '\"&gt;' . $page-&gt;post_title . '&lt;\/a&gt;&lt;br&gt;';\n}\n?&gt;<\/code><\/pre>\n\n\n\n<p>\ud83d\udccc Replace&nbsp;&#8220;your-category&#8221;&nbsp;with your desired category name.<\/p>\n\n\n\n<p><strong>3\ufe0f\u20e3 Alternative: Use Custom Taxonomies<\/strong><\/p>\n\n\n\n<p>Instead of categories, you can create a&nbsp;<strong>custom taxonomy<\/strong>&nbsp;for pages (e.g., \u201cPage Groups\u201d).<\/p>\n\n\n\n<p><strong>\ud83d\udd39 Add This Code to functions.php<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function create_page_taxonomy() {\n    register_taxonomy('page_category', 'page', array(\n        'label' =&gt; 'Page Categories',\n        'hierarchical' =&gt; true,\n        'show_admin_column' =&gt; true,\n    ));\n}\nadd_action('init', 'create_page_taxonomy');<\/code><\/pre>\n\n\n\n<p>\ud83d\udccc This will create a new taxonomy called&nbsp;<strong>Page Categories<\/strong>&nbsp;in the WordPress admin.<\/p>\n\n\n\n<p><strong>\ud83c\udfaf Best Option for You?<\/strong><\/p>\n\n\n\n<p>\u2022&nbsp;\u2705&nbsp;<strong>Use a Plugin<\/strong>&nbsp;if you want an easy, no-code solution.<\/p>\n\n\n\n<p>\u2022&nbsp;\u2705&nbsp;<strong>Use Custom Code<\/strong>&nbsp;if you prefer a lightweight, customizable option.<\/p>\n\n\n\n<p>\u2022&nbsp;\u2705&nbsp;<strong>Use Custom Taxonomies<\/strong>&nbsp;if you want a more advanced grouping system.<\/p>\n\n\n\n<p>Do you need help displaying these grouped pages on your site? \ud83d\ude0a<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Can You Group Pages by Category in WordPress? By default,&nbsp;WordPress does not support categories for pages&nbsp;(only for posts). However, you can still group pages using categories by using&nbsp;plugins or custom code. 1\ufe0f\u20e3 Using a Plugin (Easy Method) The easiest way to add&nbsp;categories to pages&nbsp;is by using a plugin. \ud83d\udccc Recommended Plugin:&nbsp;Pages with Category and Tag [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-74","post","type-post","status-publish","format-standard","hentry","category-wordpress"],"_links":{"self":[{"href":"https:\/\/notes.zj1963.com\/index.php?rest_route=\/wp\/v2\/posts\/74","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/notes.zj1963.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/notes.zj1963.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/notes.zj1963.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/notes.zj1963.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=74"}],"version-history":[{"count":1,"href":"https:\/\/notes.zj1963.com\/index.php?rest_route=\/wp\/v2\/posts\/74\/revisions"}],"predecessor-version":[{"id":75,"href":"https:\/\/notes.zj1963.com\/index.php?rest_route=\/wp\/v2\/posts\/74\/revisions\/75"}],"wp:attachment":[{"href":"https:\/\/notes.zj1963.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=74"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/notes.zj1963.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=74"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/notes.zj1963.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=74"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}