5

サイドバーに表示される最新の投稿から nofollow コードを削除したい。最新の投稿に rel=nofollow タグを追加するコードがここにあることがわかりました

テーマフォルダー/サンプルテーマ/lib/activity/plugin.php.

正確なコードは次のとおりです。

private function get_latest_posts( $post_count ) {

    // Get the latest posts
    $latest_posts = get_posts(
        array(
            'numberposts'   => $post_count,
            'order'         => 'desc',
            'orderby'       => 'date'
        )
    );

    // Create the markup for the listing
    $html = '<div class="tab-pane" id="recent">';
        $html .= '<ul class="latest-posts">';

        if( count( $latest_posts ) > 0 ) {

            foreach( $latest_posts as $post ) {

                $html .= '<li class="clearfix">';

                    // Add the small featured image
                    if( has_post_thumbnail( $post->ID ) ) {
                        $html .= '<a class="latest-post-tn fademe" href="' . get_permalink( $post->ID ) . '" rel="nofollow">';
                            $html .= get_the_post_thumbnail( $post->ID, array( 50, 50 ) );
                        $html .= '</a>';
                    } // end if

                    $html .='<div class="latest-meta">';    

                        // Add the title
                        $html .= '<a href="' . get_permalink( $post->ID ) . '" rel="nofollow">';
                            $html .= get_the_title( $post->ID );
                        $html .= '</a>';

                        // Add date posted
                        // If there's no title, then we need to turn the date into the link
                        if( strlen( get_the_title( $post->ID ) ) == 0 ) {
                            $html .= '<a href="' . get_permalink( $post->ID ) . '" rel="nofollow">';
                        } // end if

                        $html .= '<span class="latest-date">';
                            $html .= get_the_time( get_option( 'date_format' ), $post->ID );
                        $html .= '</span>';

                        // Close the anchor 
                        if(strlen( get_the_title( $post->ID ) ) == 0 ) {
                            $html .= '</a>';
                        } // end if

                    $html .='</div>';

                $html .= '</li>';
            } // end foreach

        } else {

            $html .= '<li>';
                $html .= '<p class="no-posts">' . __( "You have no recent posts.", 'standard' ) . '</p>';
            $html .= '</li>';

        } // end if/else

        $html .= '</ul>';
    $html .= '</div>';

    return $html;

} // end get_latest_posts

子テーマを使用して、このコードから nofollow タグを削除する方法を教えてください。

4

2 に答える 2

3

子テーマを制御できるので、そのウィジェットのウィジェット ゾーンを表示する呼び出しをラップして、出力を取得し、正規表現の検索/置換を実行し、結果を出力するものを使用できます。私は最近、それについてブログ記事を書きました:

WordPress ウィジェットの出力のフィルタリング

基本は、次のように、 dynamic_sidebar() を独自の関数に置き換える関数があることです。

function theme_dynamic_sidebar($index = 1) {
    // capture output from the widgets
    ob_start();
    $result = dynamic_sidebar($index);
    $out = ob_get_clean();
    // do regex search/replace on $out
    echo $out;
    return $result;
}
于 2012-12-03T22:03:55.027 に答える
1

あなたは運が悪いようです。

これはプライベートな機能であり、テーマの作成者が提供するフィルター フックはありません。

をオーバーライドしてinclude('path/to/plugin.php');、独自の変更バージョンを含めることができます。

于 2012-12-03T21:51:36.613 に答える