skip to Main Content

Good day, dear specialists. There is such a code

$categoriesForSitemap = get_categories(array(
 'hide_empty' => 1, 
 'depth' => 0, 
 'hierarchical' => false
 ));
foreach($categoriesForSitemap as $category) {
    $category_link = get_category_link($cat->cat_ID);
    $sitemap .= '<url>' . '<loc>' . get_category_link($category->term_id) . '</loc>' . '<priority>1</priority>' . '<lastmod></lastmod>' . '<changefreq>daily</changefreq>' . '</url>';
}

How can I enable adding all category pages in it? Those.

category-name/page/2/ 

category-name/page/3/
.....

and so on.

Plase help me. Sorry for my English.

2

Answers


  1. You are using WordPress so why not just use a plugin that does it for you already? There must be a plugin that is free that supports this already.

    Login or Signup to reply.
  2. First, there is no depth option in get_categories().
    Second, you set the hide_empty and hierarchical parameters yourself – as a result, you will no have ALL categories.
    Thirdly, in the loop you refer to $cat->cat_ID – it is not at all clear what.
    My advice is read the documentation before asking questions on stackoverflow.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search