• Resolved andyt963

    (@andyt963)


    Hey All

    This may sound confusing at first but should be pretty easy to fix for someone who knows their stuff.

    I have different “a name” links for every category inside each of my posts.

    The “a name” links inside the posts are the titles of the categories in my blog.

    I want to be able to link to the “a name” category position in the post from the categories page.

    For example:

    * A user click on the “designs” category of my blog.
    * They choose a post within that category.
    * The post should link to ?p=1#designs

    I have tried using:

    <a href="<?php the_permalink() ?>#<?php the_category(); ?>">

    But haven’t been able to call the current categories name into the link.

    Any clues??

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter andyt963

    (@andyt963)

    *bump* anyone?

    Are all posts assigned to only one category? If not, the following may not work as expected (that is it will work, but only makes use of the *first* category in the category list for a post):

    <?php $a_cat = get_the_category(); ?>
    <a href="<?php the_permalink(); ?>#<?php echo $a_cat[0]->category_nicename; ?>">

    Thread Starter andyt963

    (@andyt963)

    Hey Kafkaesqui

    Thanks for the reply

    As mentioned that did work but for only the first category however I do really need it to read the current category that is being viewed and insert it.

    Any further ideas?

    If “current category” means current category query (i.e. one is on a category page):

    <?php
    global $wp_query;
    $category = $wp_query->get_queried_object();
    ?>
    <a href="<?php the_permalink(); ?>#<?php echo $category->category_nicename; ?>">

    Thread Starter andyt963

    (@andyt963)

    Thank you so much Kafkaesqui you have saved me a great deal of time and trouble!

    God bless oh mighty wordpress and its wonderful community!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘A name link category help’ is closed to new replies.