WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom category link text? (5 posts)

  1. StamperTV
    Member
    Posted 3 years ago #

    This one is completely escaping me - how would you guys go about creating a link to a category within the loop, that ISN'T the generated category title? I've searched the world and figure I'm either wording my issue wrong or the answer is something simple, right under my nose.

    <?php the_category(); ?>

    Something along these lines doesn't seem to work:
    <a href="<?php the_category(); ?>">Blah</a>

    Goal: View All > = Link to category.

    Should I not be using the_category? Is my syntax off? Someone save me a bullet here. I figure 3 or 4 days of trial and error is enough on my end.

  2. keesiemeijer
    moderator
    Posted 3 years ago #

    this shows all categories as Blah linking to the categories (use in loop):

    <?php
    $categories = get_the_category();
    if(!empty($categories)) :
    ?>
    <p>View All
    <?php foreach($categories as $category) : ?>
     <a href="<?php echo get_category_link($category->cat_ID ); ?>" title="<?php echo $category->cat_name;  ?>">Blah</a>
    <?php endforeach; ?>
    </p>
    <?php endif; ?>
  3. StamperTV
    Member
    Posted 3 years ago #

    Thank you.

  4. 123milliseconds
    Member
    Posted 3 years ago #

    Please mark thread as resolved so that

    - others with similar problem can see it as resolved and will read this thread for help if they have similar problem

    - people providing help see it as resolved and will not waste time reading this post.

  5. StamperTV
    Member
    Posted 3 years ago #

    Looked for it, took a minute to figure out how. Sorry.

Topic Closed

This topic has been closed to new replies.

About this Topic