Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Comment links

  • This topic is empty.
Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #161575
    chrisburton
    Participant

    Can someone help me figure out the logic to creating links to individual comments?

    Examples:

    http://domain.com/articles/made-with-kirby/#comment-1

    OR

    http://domain.com/articles/pairing-webtype/#comment-197

    #161576
    chrisburton
    Participant

    Ooh, wait. Perhaps I can use the id column for this?

    #161577
    TheDoc
    Moderator

    That should work! (not that I know what I’m doing)

    #161581
    chrisburton
    Participant

    Haha. I agree, it should do the job.

    @TheDoc Side note: You should watch these Harvard CS lectures I have. It’s what educated me on how to use $_SESSION and a few other things.

    #161588
    chrisburton
    Participant

    Can someone tell me how to stop the permalink from adding a slash to my url?

    http://chrisburton.me/dev/articles/made-with-kirby#comment-111

    Keep clicking the hash symbol while watching the address bar.

    #161589
    __
    Participant

    How are you making the links? The slash is in your href.

    #161591
    chrisburton
    Participant

    @traq Correct but how can I stop it from adding an additional forward slash?

    Preferred when multiple clicks are triggered (stays the same):

    /made-with-kirby/#comment-111

    Reality:

    /made-with-kirby//#comment-111

    #161601
    __
    Participant

    Not sure you can (except via js, of course).

    What I was getting at is that the link you posted above doesn’t have a slash before the hash. Do you want one (and only one)? or would you be happy with no slashes at all? In the latter case, you can simply leave the slash out of the href, and it will always look like

    /made-with-kirby#comment-111

    no matter how many times you click it.

    #161632
    chrisburton
    Participant

    Do you want one (and only one)?

    Yes, exactly.

    #161644
    __
    Participant

    hmm… again, how are you creating these links? can you show me the code that writes them?

    #161645
    TheDoc
    Moderator

    Would need to see how the links are being generated in the first place.

    #161652
    chrisburton
    Participant

    The links are generated by appending the id from the database.

    Outputs domain and directory (domain.com/articles/article-title)
    
    $page = $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
    
    Inside a foreach loop, this grabs the corresponding id from each particular row
    
    $permalink = $comment['id'];
    
    Generates a link (domain.com/articles/article-title/#comment-123)
    
    echo '<a href="'.$page.'/#comment-'.$permalink.'">#</a>'
    
    #161654
    __
    Participant
    echo '<a href="'.rtrim( $page,'/' ).'/#comment-'.$permalink.'">#</a>'
    
    #161655
    chrisburton
    Participant

    As simple as rtrim(). Thank you @traq!

Viewing 14 posts - 1 through 14 (of 14 total)
  • The forum ‘Back End’ is closed to new topics and replies.