• 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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi,

    Try using this code:

    echo '<ul>';
    
    $args = array(
        'orderby'    => 'name',
        'order'      => 'ASC',
        'hide_empty' => false
    );
    
    $categoriesForSitemap = get_categories( $args );
    
    foreach ( $categoriesForSitemap as $category ) {
        echo '<li><a href="' . esc_url( get_category_link( $category->term_id ) ) . '">' . esc_html( $category->name ) . '</a></li>';
    }
    
    echo '</ul>';

    It will display list of categories. Each category will be linked to the category page.

    Thread Starter ikiterder

    (@ikiterder)

    Nazmul Hasan Robin

    Only root pages are displayed, but I need all existing ones. They are called pagination pages I think. I need links to them too. Here’s an example:

    http://sitename.com/category-name/
    http://sitename.com/category-name/page/2/
    http://sitename.com/category-name/page/3/
    http://sitename.com/category-name/page/4/
    http://sitename.com/category-name/page/5/

    • This reply was modified 4 months, 2 weeks ago by ikiterder.
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.