• I am wanting display a link within the entry head of each post like this: https://domain.com/folder/some-category/postname

    What I need is the slug (with the category) folder. I just want to add my own “https://domain.com/” in front of it. The reason I am doing this is because I would like them to have the discussion on the post in the forums (not in WordPress) instead of in the ‘comments section’.

    I will keep the directory structure and post name same. I am using permalinks and so my usual post links appear like this: https://domain.com/hello/how-are-you/

    This is the code that I have so far, it gets me to:
    https://domain.com/hello/ I see need the post slug at the end.

    <?php
    foreach((get_the_category()) as $category) {
        echo '<a href="https://xxx.com/forum/' . $category->category_nicename . '/" alt="' . $category->cat_name . '" />';
    }
    ?>Forum</a>

    I really hope someone can figure this out. Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • try

    $category->slug

    Is this what you’re after?

    <?php foreach((get_the_category()) as $category) : ?>
    <a href="https://xxx.com/forum/<?php $category->category_nicename; ?>/<?php echo $post->post_name; ?>">Forum</a>
    <?php endforeach; ?>

    ??

    NOTE: If it shouldn’t produce links for each category, then just select the first.

    <?php $first_cat = get_the_category(); $first_cat = $first_cat[0]; ?>
    <a href="https://xxx.com/forum/<?php $first_cat->category_nicename; ?>/<?php echo $post->post_name; ?>">Forum</a>

    Thread Starter intraspark

    (@intraspark)

    @alchymyth that doesn’t work, but thank you.

    @mark this works great except it is not showing the category.. I am using your 2nd code and it is making the following link:

    https://xxx.com/forum//name-of-post

    Please advise.

    Thanks

    Thread Starter intraspark

    (@intraspark)

    anyone? :/

    Can’t respond in my sleep.. ??

    Try the slug as alchymyth suggested alongside?

    <?php $first_cat = get_the_category(); $first_cat = $first_cat[0]; ?>
    <a href="https://xxx.com/forum/<?php $first_cat->slug; ?>/<?php echo $post->post_name; ?>">Forum</a>

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘PHP slug?’ is closed to new replies.