Skip to:
Content
Pages
Categories
Search
Top
Bottom

Making `from` a link in Topic View


  • Peter A. Gebhardt
    Participant

    @starship-trooper

    How can I complete the from part with a clickable link to the profile of the latest poster?

    34 posts, 2 voices - Latest reply from ...

    The user name ist Test User – it does contain a space.

Viewing 11 replies - 1 through 11 (of 11 total)

  • Peter A. Gebhardt
    Participant

    @starship-trooper

    The code developed so far (resembling the buddyPress Forum experience):

    ...
    <span id="topic_posts"><?php topic_posts_link(); ?>, </span>
    <span id="topic_voices"><?php printf( '%s voices', bb_get_topic_voices() ); ?></span>
    <span><?php if ( 1 < get_topic_posts() ) : ?>
    <?php printf(__('- <a href="%1$s">Latest reply</a> from '),attribute_escape( get_topic_last_post_link()) ) ?>
    <a href="<?php bb_option('uri'); ?>profile.php?id=<?php echo (sanitize_user(get_topic_last_poster(),true)); ?>"><?php echo get_topic_last_poster(); ?></a>

    <?php endif; ?>
    </span>

    does only generate an “User not found.” error with:

    ..../profile.php?id=Test%20User

    get_user_profile_link( $topic->topic_poster ), rather than all that sanitize/echo stuff. Can’t check it 100% since my test server is dead, but that should be right I think.


    Peter A. Gebhardt
    Participant

    @starship-trooper

    Appreciating your help – but I’m looking for linking to the profile of the last poster – not the last topic->poster

    I already spent some hours on searching the forum & the web, but there seems no feasible solution for the %20 issue.

    Oh, that’s get_user_profile_link( $topic->topic_last_poster ) then :P it seems that usernames don’t contain spaces (only the display name does), the username is converted to using a – instead of any invalid characters


    Peter A. Gebhardt
    Participant

    @starship-trooper

    Solution found – bb_user_nicename_sanitize()- needs peer review because of possible side-effects (UTF8 etc.)

    <span><?php if ( 1 < get_topic_posts() ) : ?>
    <?php printf(__('- <a href="%1$s">Latest reply</a> from '),attribute_escape( get_topic_last_post_link()) ) ?>
    <a href="<?php bb_option('uri'); ?>profile.php?id=<?php echo (bb_user_nicename_sanitize(get_topic_last_poster(),50)); ?>"><?php echo get_topic_last_poster(); ?></a>

    <?php endif; ?>
    </span>

    PS: A look into one’s database via phpadmin produces the right insights …

    I find looking at a bbPress install database pretty unnerving with all the relational IDs around the place :)


    Peter A. Gebhardt
    Participant

    @starship-trooper

    But it’s a nice place to look for nice_name’s … ;-))


    chandersbs
    Member

    @chandersbs

    Thanks for posting the solution also, I was looking at my codes if I could get a solution, but I couldn’t, when I looked back at this topic, I saw the solution already posted.


    chandersbs
    Member

    @chandersbs

    I’ve been using this code for a while now, untill I discovered in my Google webmaster tools account that it’s giving some broken URL’s. Appearantly this code only works when you have pretty URL’s turned on — which is not in my case.

    Is there a way to link it to profile id’s instead of profile names? (e.g. domain/profile.php?id=2 instead of domain/username)

    Thanks in advance.

    @chandersbs.

    See if this other code works for you.

    <a href="<?php echo get_user_profile_link(bb_get_user_id($topic->topic_last_poster)); ?>"><?php topic_last_poster(); ?></a>

    I tried it with the three permalink types without problem.


    chandersbs
    Member

    @chandersbs

    @matveb thanks that worked.

Viewing 11 replies - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.