• Resolved VIPStephan

    (@10010110)


    If a post is assigned to multiple categories it can usually be accessed at multiple respective URLs, right? So, a post in both, category 1 and category 2, can be accessed at https://example.com/category-1/post-xyz and https://example.com/category-2/post-xyz. My question now is: is it possible that the permalink to the individual post can be different in different category archives?

    For example, I have a category archive of “category 1” that lists all posts from that category and another category archive that lists posts from category 2. If a post appears in both archives (because it’s assigned to both categories) I want the link to the individual post in category archive 1 to be https://example.com/category-1/post-xyz and in category archive 2 to be https://example.com/category-2/post-xyz. How is this possible? By default the permalink will only be one domain, regardless of where the post appears.

    • This topic was modified 4 years, 5 months ago by Jan Dembowski.
Viewing 5 replies - 1 through 5 (of 5 total)
  • I haven’t seen a post with multiple URLs… usually it gets its own URL no matter how many categories it is assigned.. not sure if that is possible.

    Thread Starter VIPStephan

    (@10010110)

    If you change the permalink setting to “/%category%/%postname%/” you can most definitely access a single post on different URLs, as demonstrated here:

    https://neu.maike-lindemann.de/gedanken/euphorische-worte-fuer-plebeian-love/
    https://neu.maike-lindemann.de/neuigkeiten/euphorische-worte-fuer-plebeian-love/

    I would like the link to/URL of single posts reflect the category archive in which they appear.

    • This reply was modified 4 years, 5 months ago by Jan Dembowski.
    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    @10010110 Do not use URL shortners in these forums again. That has been abused in the past and get expanded when found. I have expanded your URLs.

    Thread Starter VIPStephan

    (@10010110)

    Sorry about that; I just didn’t want to expose the plain URL so that it doesn’t get picked up by search engines.

    Thread Starter VIPStephan

    (@10010110)

    By the way: I ended up with this:

    In category.php I have

    
    $current_category = get_query_var('cat');
    $cat_link = get_category_link($current_category);
    if(have_posts()):
    	while(have_posts()):
    		the_post();
    		set_query_var('custom_post_URL', $cat_link.basename( get_permalink()));
    		get_template_part('entry');
    	endwhile;
    endif;
    

    and in entry.php, which contains the actual link to the single post:

    
    <?php
    $post_url = get_query_var('custom_post_URL',get_the_permalink());
    ?>
    <a href="<?php echo($post_url); ?>">
    …
    …
    
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Links to posts with multiple categories’ is closed to new replies.