• axpirastore

    (@axpirastore)


    Hello,

    This might be a simple question but I have been searching and Googling about this for days.. I have a question regarding Posts & Categories.

    I have some post categories with country names (country A , Country B & Country C) and some posts (postsA, PostsB) with content. I would like to First have a sitemap that doesnt only show the primary category (now only PrimeCategory/Post) but shows ALL available URL’s & webpages. f.e. CategoryA/postA // CategoryB/PostA // CategoryA/PostB // CategoryB/PostB.

    Secondly I used some code underneath to be able to create a dynamic title on my page in the header Category + Post Title, but same problem it only shows the Primary Category.

    <?php
    $post_id = get_the_ID(); // or use the post id if you already have it
    $category_object = get_the_category($post_id);
    $category_name = $category_object[0]->name;
    echo single_post_title().' '.$category_name;

    Thank you in advance for any feedback.

    Best Regards,
    AXPIRA – Gift Delivery Shop

    • This topic was modified 5 years ago by axpirastore.
    • This topic was modified 5 years ago by axpirastore.
    • This topic was modified 5 years ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not a Requests and Feedback topic

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    $category_object[0]->name is specifically the first category found, so that’s all the code would ever do. There could be other categories in $category_object array that you could use. I assume you don’t want all displayed, rather the one used in the requested URL. This cannot be discerned from the category objects. You could get it from the global $wp_query object as one of its query vars.

    To get a sitemap that contains all possible permutations of posts and categories, it depends on what plugin is generating the sitemap. I suggest asking in that plugin’s dedicated support forum for how that could be accomplished.

    I’m a little suspicious of listing multiple URLs that all lead to the same page. Could search engines see this as “URL stuffing”, causing them to disregard your sitemap? IDK, I’m no SEO expert. You may want independent verification if this could be an issue or not.

Viewing 1 replies (of 1 total)

The topic ‘Posts Category URL & Sitemaps’ is closed to new replies.