如何根据thady_id获取好友按压消息?

时间:2017-02-15 作者:laraib

我做了很多尝试,但都没能摆脱这个困境,我使用的是他们提供的标准循环,但它仍然只显示所有线程,而不是所有消息。同时,我希望每个线程都有消息,以便在每个客户端的屏幕上显示这些消息。以下是我使用的代码:

<?php 
                      //Getting user id from query string 
                      $chat_id = $_GET[\'user_id\'];
                      if ( bp_has_message_threads( \'user_id=\'.$chat_id.\'&box=sentbox;&box=inbox;&amp;max=10&amp;amp;per_page=10\' ) ) { ?>        
                        <div class="large-center full-height-cnt">
                            <div class="body-continer">
                              <div class="head-option">
                                  <h2>Conversations between You and <span class="green-text"><?php echo bp_core_get_user_displayname( $chat_id ); ?></span> (Coach)</h2>
                              </div>
                              <div class="message-box">
                                <?php while ( bp_message_threads() ) { bp_message_thread(); ?>
                                  <div class="section-cnt">
                                    <div class="single-sectn">
                                      <div class="avatar-large">
                                            <img src="//www.gravatar.com/avatar/55197e87008006dcc554261d15335890?s=50&amp;r=g&amp;d=mm" class="avatar user-8-avatar avatar-50 photo" width="50" height="50" alt="Profile photo of akram">
                                      </div>
                                        <!-- avatar-large -->
                                            <div class="comment-box">
                                              <h3 class="name-cl"><?php echo bp_core_get_user_displayname( $chat_id ); ?><!--joe Smith-->
                                                <span class="f-right">
                                                  1 hour ago <span class="piper"> | </span> <a href="<?php bp_message_thread_delete_link(); ?>"> <i class="fa fa-close" aria-hidden="true"></i></a>
                                                </span>
                                              </h3>
                                              <span class="subject">
                                                Subject: <?php bp_message_thread_subject(); ?>
                                              </span>
                                              <p>
                                                <?php bp_message_thread_content(); ?>
                                              </p>
                                              <div class="replay-button">
                                                <a href="javascript:;">Reply</a>
                                              </div>
                                            </div>
                                        </div>
                                            <!-- single-sectn -->
                                            <div class="replay-box">
                                                <h3 class="name-cl">You
                                                  <span class="f-right">
                                                    1 hour ago <span class="piper"> | </span> <a href="javascript:;"> <i class="fa fa-close" aria-hidden="true"></i></a>
                                                  </span>
                                                </h3>
                                                <span class="subject">
                                                  Subject: Changes  Requried
                                                </span>
                                                <p>
                                                  I need to change the Program "Running in Summer"
                                                </p>
                                            </div>
                                              <!-- /.replay-box -->
                                  </div>
                                  <?php } //while?>
                                  <!-- /.section-cnt -->

                                  <div class="section-cnt">
                                    <div class="single-sectn">
                                      <div class="avatar-large">
                                            <img src="//www.gravatar.com/avatar/55197e87008006dcc554261d15335890?s=50&amp;r=g&amp;d=mm" class="avatar user-8-avatar avatar-50 photo" width="50" height="50" alt="Profile photo of akram">
                                      </div>
                                        <!-- avatar-large -->
                                            <div class="comment-box">
                                              <h3 class="name-cl">joe Smith
                                                <span class="f-right">
                                                  1 hour ago <span class="piper"> | </span> <a href="javascript:;"> <i class="fa fa-close" aria-hidden="true"></i></a>
                                                </span>
                                              </h3>
                                              <span class="subject">
                                                Subject: Changes done !
                                              </span>
                                              <p>
                                                  Hi, i have made changes in your planner 2016<br>
                                                  Please check the programe "Running in summer" <br>
                                                  sesstion...
                                              </p>
                                              <div class="replay-button">
                                                <a href="javascript:;">Reply</a>
                                              </div>
                                            </div>
                                        </div>
                                            <!-- single-sectn -->
                                            <div class="replay-box">
                                                <h3 class="name-cl">You
                                                  <span class="f-right">
                                                    1 hour ago <span class="piper"> | </span> <a href="javascript:;"> <i class="fa fa-close" aria-hidden="true"></i></a>
                                                  </span>
                                                </h3>
                                                <span class="subject">
                                                  Subject: Changes  Requried
                                                </span>
                                                <p>
                                                  I need to change the Program "Running in Summer"
                                                </p>
                                            </div>
                                              <!-- /.replay-box -->


                                  </div>

                              </div>
                              <!-- /.message-box -->
                            </div>

                        </div>
                        <?php } else { //.if  ?>
                        <?php //else { ?>
                        <div class="large-center full-height-cnt">
                            <div class="body-continer">
                              <div class="head-option">
                                  <h2>Conversations between You and <span class="green-text"><?php echo bp_core_get_user_displayname( $chat_id ); ?></span> (Coach)</h2>
                              </div>
                              <div class="message-box">
                              Sorry, No Messages Found ... !
                              </div>
                            </div>
                        </div>
                        <?php  } ?>
它只显示一条消息,而我想要所有消息,或者我可以说这两个用户之间的整个聊天。有人帮我吗?

1 个回复
最合适的回答,由SO网友:majick 整理而成

再深入一点BP Messages file 你会看到的bp_message_thread_content() 仅输出线程中的最后一条消息。与类似bp_message_thread_subject(). bp_message_thread() 设置最后一条消息数据,但不设置其他消息数据。

相反,看起来你想要一个新的BP_Messages_Thread_Template 为线程输出消息。例如:。

 while ( bp_message_threads() ) {
      bp_message_thread();
      $thread_id = bp_get_message_thread_id();
      $order = \'DESC\'; // or \'ASC\'
      new BP_Messages_Thread_Template( $thread_id, $order );

      // so that instead of `bp_message_thread_content()
      while ( bp_thread_messages() ) {
          bp_thread_the_message();
          bp_the_thread_message_content();
      }

  }
该类有更多的方法/函数,但这应该会让您朝着正确的方向发展…:-)

相关推荐

无法在模板函数.php中使用IS_HOME

我试图在标题中加载一个滑块,但只在主页上加载。如果有帮助的话,我正在使用Ultralight模板。我正在尝试(在template functions.php中)执行以下操作:<?php if ( is_page( \'home\' ) ) : ?> dynamic_sidebar( \'Homepage Widget\' ); <?php endif; ?> 但这行不通。现在,通过快速的google,我似乎需要将请