<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                WordPress會根據WordPress主題中的comments.php文件中的設置和代碼在主題中顯示注釋。 ## 簡單的評論循環 ``` <?php //Get only the approved comments $args = array( 'status' => 'approve' ); // The comment Query $comments_query = new WP_Comment_Query; $comments = $comments_query->query( $args ); // Comment Loop if ( $comments ) { foreach ( $comments as $comment ) { echo '<p>' . $comment->comment_content . '</p>'; } } else { echo 'No comments found.'; } ?> ``` comments.php模板包含將注釋從數據庫中拉出并顯示在主題中的所有邏輯。 在我們探索模板文件之前,您需要知道如何在相應的頁面(如single.php)上拉入部分模板文件。 您將包含注釋模板標簽在條件語句中,所以comments.php只有在有意義的情況下被拉入。 ```php // 如果發表評論,或者至少有一個評論,請加載評論模板。 if ( comments_open() || get_comments_number() ) : comments_template(); endif; ``` ## 另一個Comments.php示例 以下是Twenty Thirteen主題中包含的comments.php模板的示例: ``` <?php /** * 用于顯示評論的模板。 * * 包含評論和評論表單的頁面區域。 * * @package WordPress * @subpackage Twenty_Thirteen * @since Twenty Thirteen 1.0 */ /* * If the current post is protected by a password and the visitor has not yet * entered the password we will return early without loading the comments. */ if ( post_password_required() ) return; ?> <div id="comments" class="comments-area"> <?php if ( have_comments() ) : ?> <h2 class="comments-title"> <?php printf( _nx( 'One thought on "%2$s"', '%1$s thoughts on "%2$s"', get_comments_number(), 'comments title', 'twentythirteen' ), number_format_i18n( get_comments_number() ), '<span>' . get_the_title() . '</span>' ); ?> </h2> <ol class="comment-list"> <?php wp_list_comments( array( 'style' => 'ol', 'short_ping' => true, 'avatar_size' => 74, ) ); ?> </ol><!-- .comment-list --> <?php // Are there comments to navigate through? if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : ?> <nav class="navigation comment-navigation" role="navigation"> <h1 class="screen-reader-text section-heading"><?php _e( 'Comment navigation', 'twentythirteen' ); ?></h1> <div class="nav-previous"><?php previous_comments_link( __( '&larr; Older Comments', 'twentythirteen' ) ); ?></div> <div class="nav-next"><?php next_comments_link( __( 'Newer Comments &rarr;', 'twentythirteen' ) ); ?></div> </nav><!-- .comment-navigation --> <?php endif; // Check for comment navigation ?> <?php if ( ! comments_open() && get_comments_number() ) : ?> <p class="no-comments"><?php _e( 'Comments are closed.' , 'twentythirteen' ); ?></p> <?php endif; ?> <?php endif; // have_comments() ?> <?php comment_form(); ?> </div><!-- #comments --> ``` ## 打破comments.php 以上的comment.php可以分解到下面的部分,以便更好的理解。 - 模板頭 - 評論標題 - 評論列表 - 評論分頁 - 評論是封閉的消息。 ## 模板頭 用于定義一個模板。 ``` <?php /** * The template for displaying Comments. * * The area of the page that contains comments and the comment form. * * @package WordPress * @subpackage Twenty_Thirteen * @since Twenty Thirteen 1.0 */ ``` 接下來,有一個測試來看看帖子是否受密碼保護,如果是,則停止處理該模板。 ``` /* * If the current post is protected by a password and the visitor has not yet * entered the password we will return early without loading the comments. */ if ( post_password_required() ) return; ?> ``` 最后,有一個測試,看看是否有與此帖子相關聯的評論。 ``` <div id="comments" class="comments-area"> <?php if ( have_comments() ) : ?> ``` ## 評論標題 打印出在評論上方顯示的標題。 >[warning] 注意:使用`_nx()`翻譯方法,因此其他開發人員可以提供替代語言翻譯。 ``` <h2 class="comments-title"> <?php printf( _nx( 'One thought on "%2$s"', '%1$s thoughts on "%2$s"', get_comments_number(), 'comments title', 'twentythirteen' ), number_format_i18n( get_comments_number() ), '<span>' . get_the_title() . '</span>' ); ?> </h2> ``` ## 評論列表 以下代碼片段使用`wp_list_comments()`函數獲取注釋的有序列表。 ``` <ol class="comment-list"> <?php wp_list_comments( array( 'style' => 'ol', 'short_ping' => true, 'avatar_size' => 74, ) ); ?> </ol><!-- .comment-list --> ``` ## 評論分頁 檢查是否有足夠的評論,以便添加評論導航,如果是,創建評論導航。 ``` <?php // Are there comments to navigate through? if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : ?> <nav class="navigation comment-navigation" role="navigation"> <h1 class="screen-reader-text section-heading"><?php _e( 'Comment navigation', 'twentythirteen' ); ?></h1> <div class="nav-previous"><?php previous_comments_link( __( '&larr; Older Comments', 'twentythirteen' ) ); ?></div> <div class="nav-next"><?php next_comments_link( __( 'Newer Comments &rarr;', 'twentythirteen' ) ); ?></div> </nav><!-- .comment-navigation --> <?php endif; // Check for comment navigation ?> ``` ## 評論是封閉的消息。 如果評論未打開,則顯示一條表示它們已關閉的行。 ``` <?php if ( ! comments_open() && get_comments_number() ) : ?> <p class="no-comments"><?php _e( 'Comments are closed.' , 'twentythirteen' ); ?></p> <?php endif; ?> ``` ## 結束 本節結束評論循環,包括注釋表單,并關閉評論包裝器。 ``` <?php endif; // have_comments() ?> <?php comment_form(); ?> </div><!-- #comments --> ``` ## 評論分頁 如果您有很多評論(這使您的頁面很長),那么分頁您的評論有很多潛在的好處。 分頁有助于提高頁面加載速度,特別是在移動設備上。 啟用評論分頁是分兩步完成的。 在WordPress中啟用分頁評論,方法是進入“Settings”>“Discussion”,并選中“Break comments into pages”框。 您可以輸入“每頁評論數量”的任意數字。 打開您的comments.php模板文件,并添加以下行,您希望出現評論分頁。 ``` <div class="pagination"> <?php paginate_comments_links(); ?> </div> ``` ## 替代評論模板 在某些情況下,您可能希望在主題中顯示您的評論。 為此,您將構建一個備用文件(例如,short-comments.php),并調用如下: ``` <?php comments_template( '/short-comments.php' ); ?> ``` 用于替代注釋模板的文件的路徑應該是相對于當前的主題根目錄,并且包括任何子文件夾。 所以如果自定義注釋模板在主題中的文件夾中,調用它可能看起來像這樣: ``` <?php comments_template( '/custom-templates/alternative-comments.php' ); ?> ``` ## 參考方法 - wp_list_comments() : 根據各種參數(包括在管理區域中設置的參數)顯示帖子或頁面的所有注釋。 - comment_form() : 此標簽輸出完整的注釋表單以在模板中使用。 - comments_template() : 加載在第一個參數中指定的注釋模板 - paginate_comments_links() : 為當前帖子的評論創建分頁鏈接。 - get_comments() : 檢索可能使用參數的注釋 - get_approved_comments() : 檢索已提供的帖子ID的批準注釋。 ## 檢索評論元素的函數參考 - get_comment_link() - get_comment_author() - get_comment_date() - get_comment_time() - get_comment_text()
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看