• Hey all, I’m probably having a complete brain meltdown but I have to ask this.

    From my homepage, clicking on any Sidebar Catagory, then clicking on a Post, I get to that Post’s single page. I want to create a link at the top of that Post’s single page going back one “page” to the Category.

    The thing is I’m not going back to a real, static page that the browser loads, right? It’s all dynamically created/loaded. How do I get the user back there?

    I commented out the previous and next links, didn’t really like them…

    I’m sure this is a total brainfart so thanks for helping out. Joe

Viewing 9 replies - 1 through 9 (of 9 total)
  • So why can’t you put the literal uri of the “back one page – Category” at the top of the post when you create it? I mean…you already know what category you’re going to insert the post into…or am I totally misunderstanding?

    I like this:

    https://jp.jixor.com/plugins/bread-crumb-trail/

    ‘bread crumb trails’ make it easy for the user to see where they are, and to quickly go back to the category, etc..

    Thread Starter wwjoe

    (@wwjoe)

    Hey guys, thanks for replying. I’m new to PHP and am probably not explaining myself correctly. I’m not sure what URI is but I would assume it is equivalent to URL.

    In an “old school” website, with just static pages, no dynamic page creation or PHP, you could put a simple text link to another page/file, and your browser would load it up.

    a href=”whateverpage.html”> whateverpage </a

    If all of the pages in WP are created on the fly, where the info is pulled from DB’s and stuff can links work the same way?

    Example: From your Sidebar, when you click on a Category you see all of the Posts listed for that Category. You can click on one, and that Post is loaded into it’s own page using the Single.php template. (at least for me)

    Clicking on a Category uses the archive.php template and loads the Category you chose. Let’s say you’re reading a Post in a Categroy called Cars. How can you put a simple text link from that Post’s individual page, back to the Cars Category page, where all the Posts are listed, when the link address would change everytime you view a Post in a different Category. The Category page you link back to would change depending on what Category’s Post’s you were viewing.

    Man I’m not even sure if I get this anymore….. ??

    Let me know how I can be any clearer if this dosen’t explain what I mean. Thanks for helping everyone, I really appreceiate it. Joe

    https://www.worldwidejoe.com

    Thread Starter wwjoe

    (@wwjoe)

    Here’s what I’ve got, something as simple as this..

    When viewing any Post as a single page, it’s using the single.php template. In this template, in the Loop, near the top of the page I placed this line of code:

    <?php the_category(); ?>

    That grabs the current Post’s Category and puts it in a link.
    Damn.

    I did try to make the link this way but it didn’t work:

    a href=”Back to <? php the_category(); ?>

    yes, left out the beginning tag so it prints in this post.

    I thougt that might just print the Category name and have all 3 words as the link. I think maybe some useage of the Echo command may help but I still don’t know squat about PHP to know. Thanks

    How about this:

    <a href="<?php bloginfo('wpurl'); ?>/">Home</a> &raquo; <?php the_category(', ') ?> &raquo;

    Of course if you do not want the ‘home’ link, you can remove that part.`

    Thread Starter wwjoe

    (@wwjoe)

    Very close Aleister, I put in “Back to Projects” instead of Home, and only that text became the link, which is exactly what I wanted. The problem was it took me back to my Homepage instead of the Category with all of the Post lisings, and the actual Post didn’t show up in the page. I have to say I don’t fully get the mechanics of the code yet,but I’ll keep tweaking and update. Thanks! Joe

    Ok, I finally get what you are trying to do ??

    One of the reasons it would not work before is that the_category cannot be used within a link, since it returns a link.

    Try this out:

    <?php
    foreach((get_the_category()) as $cat) {
    $cid = $cat->cat_ID;
    $cname = $cat->cat_name;
    }
    echo '<a href="' . get_category_link($cid) . '">Back to ' . $cname . '</a>';
    ?>

    It loops through the current posts categories, grabs the current cat’s ID and name, and creates a link.

    Of course, This will only work nicely if each post only has one category assigned to it. If you have more, it will show the last one, since it will be the last pass of the loop ??

    Did it work? ??

    Thread Starter wwjoe

    (@wwjoe)

    Hey Aleister, sorry I didn’t reply sooner, worked all week…

    As for you solution, absolutely perfect, that is exactly what I was looking for. Thanks for the help my friend, I really appreceiate it. Joe

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Need help creating a link’ is closed to new replies.