• Resolved nhinshaw

    (@nhinshaw)


    Hello All,
    I have a question about generating a link path to a page of grouped posts. Currently there is a landing page that has 6 parent categories listed with a “see all link”. The link is set up to reference the category number:
    <a href="<?php bloginfo('url');?>/?cat=<?php echo $category->term_id ?>" class="link long-link"><span><?php echo $category->name;?></span></a>

    However I would like to have a semantic url. I have accomplished this elsewhere on the site by utilizing this code in the link:
    <a href="<?php bloginfo('url');?>/<?php echo $category->slug;?>" class="link long-link"><span><?php echo $category->name;?></span></a>

    However this won’t work since I also need to include the post parent. For example there are 6 categories that reside within the parent Success Stories. I cannot just hard code in the parent since this is used across multiple sections.

    Any help would be greatly appreciated – please let me know if I can clarify any of the above.

    Thanks!
    Nathan

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter nhinshaw

    (@nhinshaw)

    Thanks alchymyth. Perhaps I am missing something but I am not quite able to get this to work how I want it to. Placing <?php get_category_link( $category_id ); ?> does indeed get the parent to show up, but I am still unable to list the child.

    For example I am able to get the parent “Success Stories” to be added to the link path, but the destination category e.g. “Administrative” does not get added.

    Is there something that I am omitting?

    Thanks!

    Thread Starter nhinshaw

    (@nhinshaw)

    I resolved this issue by utilizing the following code:
    <?php foreach((get_the_category()) as $category) { $category->cat_name . ' '; } ?><a href="<?php echo get_category_link(get_cat_id($category->cat_name)); ?>"><?php echo $category->cat_name ?></a>

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Dynamically generate link path to category posts’ is closed to new replies.