Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #399

    I am wanting to include a php code which will produce a link above each post. Code link will be something like this:

    Can the support staff, please provide a PHP code, where the above link can be accomplished and place in the theme file (I know where to place it). I would need the category name and slug pulled from the post. It should work with my permalinks settings.

    Thank you


    and this is where I’m stuck:


    foreach((get_the_category()) as $category) {

    echo ‘category_nicename . ‘/” alt=”‘ . $category->cat_name . ‘” />’;



    Not sure how to add the URL slug after the category name.

    Please advise.



    That didn’t come out right, please see the code that I have so far here:


    Can you clarify exactly what you’re trying to do?

    From your description in the 1st post, you want to add a link – by the looks of the code, you’re trying to add a link for each category.

    Either way, this code should get you started:

    //get all blog categories regardless of whether on this post or not
    $categories = get_categories('title_li=&orderby=name&hide_empty=0');

    //get the categories which are attached to this post
    $categories = get_the_category();

    if ($categories) {

    foreach($categories as $category) {
    $output .= "<a href='".get_bloginfo('home')."/forum/".$category->category_nicename."/' id='".$category->category_nicename."'>".$category->cat_name."</a>";


    Important Note: You must delete or comment out one of the $categories declarations depending on your intentions for this code.

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘PHP variable for post link?’ is closed to new replies.