Skip to:
Content
Pages
Categories
Search
Top
Bottom

search.php enhancement request


  • chrishajer
    Participant

    @chrishajer

    I’ve modified search.php a bit to make the results a little more readable (to my eye) and I was wondering how to get the poster name, to display with the results for recent posts and relevant posts.

    I would like to display something like:

    <a href="<?php post_link(); ?>"><?php topic_title($bb_post->topic_id); ?></a> <small><?php _e('Posted') ?> <?php echo date(__('F j, Y, h:i A'), bb_get_p

    ost_time()); ?></small> [BY MEMBER]

    the [BY MEMBER] part, to get the name of the member who made the post that is listed is the part I need help with. Thank you.

Viewing 9 replies - 1 through 9 (of 9 total)
  • You should be able to do this:

    get_user_name($bb_post->poster_id)

    Tell me if that doesn’t work.


    chrishajer
    Participant

    @chrishajer

    That does not work :)

    Here is the code I am using:

    <?php foreach ( $recent as $bb_post ) : ?>

    <li><a href="<?php post_link(); ?>"><?php topic_title($bb_post->topic_id); ?></a><small> <?php _e('Posted') ?> <?php echo date(__('F j, Y, h:i A'), bb_get_post_time()); ?><?php _e(' by ')?><?php get_user_name($bb_post->poster_id) ?></small>

    seems like it should work. It doesn’t error out, it’s just blank after the ” by “

    Is there a list of functions, similar to the WP codex, where I could learn about them?

    Thanks.


    chrishajer
    Participant

    @chrishajer

    bb_get_user($bb_post->poster_id) also did not work (does not error, just shows no output.)

    also

    $bb_post->poster_id does not return anything either.

    Try this

    echo bb_get_user($bb_post->poster_id)->user_login

    Or you can try to do it the way topics do it and just use this:

    post_author_link();

    That will also return the name as a link to their webpage.

    Worth a try I guess.

    If neither of those work, you need to echo $bb_post->poster_id and see if you’re getting anything. If not, you gotta figure out wtf $bb_post contains.


    chrishajer
    Participant

    @chrishajer

    OK – will try. Thank you for your help.


    chrishajer
    Participant

    @chrishajer

    <?php _e(' by ')?><?php echo bb_get_user($bb_post->poster_id)->user_login ?>

    Returns the user’s name. Perfect. Thanks.


    chrishajer
    Participant

    @chrishajer

    Update: the above was working, but on the command line, php -l complained:

    parse error, unexpected T_OBJECT_OPERATOR in … that line

    I got this to work:

    <?php _e(' by ') ?><a href="<?php user_profile_link($bb_post->poster_id); ?>"><?php echo get_user_name($bb_post->poster_id); ?></a>

    That’s what was suggested initially: I’ m not sure what I did wrong the first time around, but this is what is working now, with no parse errors. Thanks.


    chrishajer
    Participant

    @chrishajer

    I wonder if the problem with this line:

    bb_get_user($bb_post->poster_id)->user_login

    is related to this style syntax and could be fixed in a similar manner (if necessary):

    https://bbpress.org/forums/topic/401?replies=42#post-2140

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.
Skip to toolbar