0

I've added the following code to my content.php which works great except the words '⟵ Back to' are a separate link to the 'category name' (news). I would like the hover to highlight the complete sentence as one item. EG:

⟵ Back to News

<a class"back-link" href="<?php $cat = get_the_category(); $cat = $cat[0]; echo get_category_link($cat->cat_ID); ?>">⟵ Back to <?php the_category ( ' ') ?></a>

Hello - I nearly works!! But I have two categories, 'news 'and 'members'. The link is correct but the category always says 'News' even when it should be 'Members'. Here's my code: <a class"back-link" href="<?php $cat = get_the_category(); $cat = $cat[0]; echo get_category_link($cat->cat_ID); ?>">⟵ Back to <?php echo get_cat_name( $cat ); ?></a>

  • Please consider accepting my answer if this has worked for you. Good luck! – Pim Oct 10 '16 at 22:44
  • I've updated my answer, let me know if it works for you! – Pim Oct 11 '16 at 20:59
  • Can you update your question? It will be easier than in the comments. – Pim Oct 12 '16 at 10:27
  • $cat[0] always gets the first category. If you have multiple categories, you should provide the full snippet of code. Or use $cat[1] where you need the second one. – Pim Oct 12 '16 at 10:28
  • I don't understand, sorry. I just want a back to the parent category link at the bottom of my single post view based on the category that the post is tagged with. So if a post is tagged 'news' the link will say '⟵ Back to News' and if the post is tagged 'member' the link will say '⟵ Back to Members'. At the moment my code is in content.php. Is there are better way to do this? – Gordon Langley Oct 12 '16 at 10:38
-1

Use echo get_cat_name( $cat ); instead of the_category() inside the link. the_category() returns a link, so you will have a link within a link.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.