Skip to:
Content
Pages
Categories
Search
Top
Bottom

Last rely, query_posts and link to the reply.

  • hello,

    I try desperately to create some kind of widget for my blog with last forum entries .

    I think query_posts was indicated because it is simple and effective.

    here is the code I use to fully control the design of my widget.

    <div id=”lastreply”>

    <?php

    query_posts(“post_type=reply”);

    while (have_posts()) : the_post();

    ?>

    <div class=”post”>

    <div class=”thumb”><?php echo get_avatar( get_the_author_id() , 60 ); ?></div>

    <h4>” rel=”bookmark”><?php the_title(); ?></h4>

    <small>De <?php the_author_posts_link(); ?> <span class=”red”>♥</span> <span class=”tag”><?php the_tags(‘#’,’, #’); ?></span></small>

    <?php the_excerpt(); ?>

    </div><!– fin de post –>

    <?php endwhile; ?>

    </div><!– last reply–>

    I have 3 problems so that my poor php skills prevents me to solve.

    1 / the title is not good, it starts with “reply to” it would have been clearer to the title of the topic directly.

    2 / the link isn’t the link to topic but the link for the answer!

    3 / but it’s going to be warmer, I wish to join the last replies to the last comment into a single widget, except that query_posts doesn’t work with the comments ^ ^

    would you have a little time to devote to my request? Thank you in advance.

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

  • Anointed
    Participant

    @anointed

    the bbPress plugin comes with 2 widgets already. You can have both the most recent topics and most recent replies, plus a few others.

    If you are trying to build a custom widget, then look at the bbPress widget code file to see how it is done. It will help a lot.

    Thank you for your answer,

    But I can’t integrate the widget as I wish in my design.

    Indeed, I can’t integrate the excerpt of the replies, I can’t properly control the CSS and I can’t (of course) include the latest comments in the last forums’ replies.

    I started by looking at the widget code by default, but I can’t decrypt properly.

    query_posts is very simple and I usually use it in my templates; is much more customizable.


    Anointed
    Participant

    @anointed

    That is exactly why I mentioned the widget file. If you look closely at the code you will see that the widget code actually does use the wordpress loop.

    Check out line 542 where the arguments for the loop are set followed by a standard WordPress loop format. While the terminology is a little different, the concept of bbPress loops and WordPress loops is exactly the same.

    oO last replies are on ligne 749 no?

    but thank you, i change ligne 750

    <div id="lastreply">

    <?php while ( bbp_replies() ) : bbp_the_reply(); ?>

    <div class="post">
    <h4>

    <?php
    $author_link = bbp_get_reply_author_link( array( 'type' => 'both', 'size' => 60 ) );
    $reply_link = '' . bbp_get_reply_topic_title() . '';

    /* translators: bbpress replies widget: 1: reply author, 2: reply link, 3: reply date, 4: reply time */

    printf( _x( $show_date == 'on' ? '%1$s on %2$s, %3$s, %4$s' : '%1$s on %2$s', 'widgets', 'bbpress' ), $author_link, $reply_link, get_the_date(), get_the_time() );
    ?>

    </h4>
    <?php the_excerpt(); ?>

    </div><!-- fin de post -->

    <?php endwhile; ?>

    </div><!-- fin du last reply-->

    and it’s ok :) but I am afraid that the next bbpress update overwrites the change

    thx a lot for your help :)


    John James Jacoby
    Keymaster

    @johnjamesjacoby

    Copy and paste the code you need into a custom widget like you were doing initially.

    Hello,

    thank you board, I tried, but it doesn’t work.

    I copied this code in my page function.php of my theme. but no widget is created.

    /**
    * bbPress Replies Widget
    *
    * Adds a widget which displays the replies list
    *
    * @since bbPress (r2653)
    *
    * @uses WP_Widget
    */
    class BBP_Replies_Widget2 extends WP_Widget {

    /**
    * Register the widget
    *
    * @since bbPress (r3389)
    *
    * @uses register_widget()
    */
    function register_widget() {
    register_widget( 'BBP_Replies_Widget2' );
    }

    /**
    * bbPress Replies Widget
    *
    * Registers the replies widget
    *
    * @since bbPress (r2653)
    *
    * @uses apply_filters() Calls 'bbp_replies_widget_options' with the
    * widget options
    */
    function BBP_Replies_Widget2() {
    $widget_ops = apply_filters( 'bbp_replies_widget_options', array(
    'classname' => 'widget_display_replies',
    'description' => __( 'balbalbalbalbalbalba.', 'bbpress' )
    ) );

    parent::WP_Widget( false, 'bbPress Reply List 2', $widget_ops );
    }

    /**
    * Displays the output, the replies list
    *
    * @since bbPress (r2653)
    *
    * @param mixed $args
    * @param array $instance
    * @uses apply_filters() Calls 'bbp_reply_widget_title' with the title
    * @uses bbp_set_query_name() To set the query name to 'bbp_widget'
    * @uses bbp_reset_query_name() To reset the query name
    * @uses bbp_has_replies() The main reply loop
    * @uses bbp_replies() To check whether there are more replies available
    * in the loop
    * @uses bbp_the_reply() Loads up the current reply in the loop
    * @uses bbp_get_reply_author_link() To get the reply author link
    * @uses bbp_get_reply_author() To get the reply author name
    * @uses bbp_get_reply_id() To get the reply id
    * @uses bbp_get_reply_url() To get the reply url
    * @uses bbp_get_reply_excerpt() To get the reply excerpt
    * @uses bbp_get_reply_topic_title() To get the reply topic title
    * @uses get_the_date() To get the date of the reply
    * @uses get_the_time() To get the time of the reply
    */
    function widget( $args, $instance ) {

    extract( $args );

    $title = apply_filters( 'bbp_replies_widget_title', $instance['title'] );
    $max_shown = !empty( $instance['max_shown'] ) ? $instance['max_shown'] : '5';
    $show_date = !empty( $instance['show_date'] ) ? 'on' : false;

    // Query defaults
    $replies_query = array(
    'post_status' => join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) ),
    'posts_per_page' => $max_shown,
    'order' => 'DESC'
    );

    // Set the query name
    bbp_set_query_name( 'bbp_widget' );

    // Get replies and display them
    if ( bbp_has_replies( $replies_query ) ) :

    echo $before_widget;
    echo $before_title . $title . $after_title; ?>

    <div id="lastreply">

    <?php while ( bbp_replies() ) : bbp_the_reply(); ?>

    <div class="post">
    <h4>

    <?php
    $author_link = bbp_get_reply_author_link( array( 'type' => 'both', 'size' => 80 ) );
    $reply_link = '<a href="' . esc_url( bbp_get_reply_url() ) . '" title="' . bbp_get_reply_excerpt( bbp_get_reply_id(), 50 ) . '">' . bbp_get_reply_topic_title() . '</a>';

    /* translators: bbpress replies widget: 1: reply author, 2: reply link, 3: reply date, 4: reply time */

    printf( _x( $show_date == 'on' ? '%1$s on %2$s, %3$s, %4$s' : '%1$s on %2$s', 'widgets', 'bbpress' ), $author_link, $reply_link, get_the_date(), get_the_time() );
    ?>

    </h4>
    <?php the_excerpt(); ?>
    <div class="clearfix"></div>
    </div><!-- fin de post -->

    <?php endwhile; ?>

    </div><!-- fin du last reply-->

    <?php echo $after_widget;

    endif;

    bbp_reset_query_name();
    }

    /**
    * Update the forum widget options
    *
    * @since bbPress (r2653)
    *
    * @param array $new_instance The new instance options
    * @param array $old_instance The old instance options
    */
    function update( $new_instance, $old_instance ) {
    $instance = $old_instance;
    $instance['title'] = strip_tags( $new_instance['title'] );
    $instance['max_shown'] = strip_tags( $new_instance['max_shown'] );
    $instance['show_date'] = strip_tags( $new_instance['show_date'] );

    return $instance;
    }

    /**
    * Output the reply widget options form
    *
    * @since bbPress (r2653)
    *
    * @param $instance Instance
    * @uses BBP_Replies_Widget::get_field_id() To output the field id
    * @uses BBP_Replies_Widget::get_field_name() To output the field name
    */
    function form( $instance ) {
    $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
    $max_shown = !empty( $instance['max_shown'] ) ? esc_attr( $instance['max_shown'] ) : '';
    $show_date = !empty( $instance['show_date'] ) ? esc_attr( $instance['show_date'] ) : ''; ?>

    <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" /></label></p>
    <p><label for="<?php echo $this->get_field_id( 'max_shown' ); ?>"><?php _e( 'Maximum replies to show:', 'bbpress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_shown' ); ?>" name="<?php echo $this->get_field_name( 'max_shown' ); ?>" type="text" value="<?php echo $max_shown; ?>" /></label></p>
    <p><label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Show post date:', 'bbpress' ); ?> <input type="checkbox" id="<?php echo $this->get_field_id( 'show_date' ); ?>" name="<?php echo $this->get_field_name( 'show_date' ); ?>" <?php checked( 'on', $show_date ); ?> /></label></p>

    <?php
    }
    }

    sorry, I feel as bad as otter. :'(

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