• Resolved Julie

    (@habannah)


    I’ve got this on category archive pages and everything works well:

    <?php
    $category = get_category( get_query_var('cat') );
    $current_category = single_cat_title("", false);
    
    if ( ! empty( $category ) )
    
    echo '<div class="tax-feed"><p style="text-align: right; padding-right: 2px;">Subscribe to the <strong>' . $current_category . '</strong> category: <a href="https://www.feedly.com/home#subscription/feed/' . get_category_feed_link( $category->cat_ID ) . '" title="Subscribe to the ' . $current_category . ' category via Feedly" rel="nofollow">Via Feedly</a> | <a href="' . get_category_feed_link( $category->cat_ID ) . '" title="Subscribe to the RSS feed for the ' . $current_category . ' category" rel="nofollow">Via RSS</a></p></div>';
    ?>

    Next I’ve got this on tag archive pages, but the Feedly link doesn’t work:

    <?php
    $category = get_category( get_query_var('cat') );
    $current_category = single_cat_title("", false);
    
    if ( ! empty( $category ) )
    
    echo '<div class="tax-feed"><p style="text-align: right; padding-right: 2px;">Subscribe to the <strong>' . $current_category . '</strong> topic: <a href="https://www.feedly.com/home#subscription/feed/' . get_tag_feed_link( $category->tag_ID ) . 'feed/" title="Subscribe to the ' . $current_category . ' topic via Feedly" rel="nofollow">Via Feedly</a> | <a href="' . get_tag_feed_link( $category->tag_ID ) . 'feed/" title="Subscribe to the RSS feed for the ' . $current_category . ' topic" rel="nofollow">Via RSS</a></p></div>';
    ?>

    The Feedly link doesn’t output this part of the URL (though the rest of the link is fine):

    ' . get_tag_feed_link( $category->tag_ID ) . '

    I find it really strange that this code works for the tag RSS feed link but not the tag Feedly link. Any ideas why, and how I could fix it?

    I’d also like to display the links on custom taxonomy archives and am wondering whether I’ll need different code for those, too.

    Thanks in advance for any help offered!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    You are trying to get the current tag from the ‘cat’ query var. This is incorrect. I believe the correct query var is ‘tag’.

    To avoid different code for every template, switch to the more generic get term family of functions. This will require the current taxonomy being specified. It too can be determined from query vars, or at least inferred. Like if ‘cat’ is set, the taxonomy is ‘category’. Consider the previous line pseudocode, it glosses over some important PHP syntax in order to illustrate the basic logic.

    Thread Starter Julie

    (@habannah)

    Thanks very much for your help. I’ve tried the following on the tag archive pages, but the Feedly link still doesn’t work. Everything else works as expected (and just like the other code I was using).

    <?php
    $term = get_term( get_query_var('tag') );
    $current_category = single_cat_title("", false);
    
    if ( ! empty( $term ) )
    
    echo '<div class="tax-feed right">Subscribe to the <strong>' . $current_category . '</strong> topic: <a href="https://www.feedly.com/home#subscription/feed/' . get_term_feed_link( $term->tag_ID ) . 'feed/" title="Subscribe to the ' . $current_category . ' topic via Feedly" rel="nofollow">Via Feedly</a> | <a href="' . get_term_feed_link( $term->tag_ID ) . 'feed/" title="Subscribe to the RSS feed for the ' . $current_category . ' topic" rel="nofollow">Via RSS</a></div>';
    ?>

    Am I still doing something wrong? Thanks!

    Moderator bcworkz

    (@bcworkz)

    Yes, get_term() requires you specify the taxonomy (‘post_tag’) the term belongs to. Additionally, the first parameter needs to be the term ID, not the name. Try using get_term_by().

    get_term_feed_link() also requires a taxonomy parameter.

    Thread Starter Julie

    (@habannah)

    Thanks again for the advice. It’s not working at all anymore with get_term_by, though I imagine I’m still doing it wrong.

    However, I realised that since the only problem with my original code was that the Feedly link wasn’t working, I just decided to do it manually by writing down the path until the term name and just using $current_category to add the term name, followed by /feed/. It’s not elegant, but it works as intended and doesn’t give me a headache ??

    Your help has been much appreciated — cheers!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Correct Way to Get Taxonomy Feed Link?’ is closed to new replies.