0

会社のウェブサイトの CMS として wordpress を使用しています。同じ行動喚起コンテンツを挿入したいページが 5 ~ 10 ページあります。

投稿のコンテンツをページに埋め込むためのショートコードを作成するにはどうすればよいですか?

ありがとうスティーブン。

4

1 に答える 1

1

私はこれをテストしていませんが、おそらく次のようなものが必要になるでしょう:

function create_call_to_action_shortcode( $atts ) {
        $call_to_action_content = '';
        $query = new WP_Query( array( 'p' => $post_id, 'no_found_rows' => true ) );

        if( $query->have_posts() ) {
            $query->the_post();

            remove_filter( 'the_content', 'sharing_display', 19);

            $call_to_action_content = apply_filters( 'the_content', get_the_content() );

            add_filter( 'the_content', 'sharing_display', 19);

            wp_reset_postdata();
        }

        return $call_to_action_content;
}

add_shortcode( 'call_to_action', 'create_call_to_action_shortcode' );`

あなたのページ (または他の投稿) では[call_to_action]、ページ/投稿のコンテンツに挿入するだけです。

ショートコードの詳細については、こちらを参照してください。:)

編集:

投稿コンテンツから共有ボタンを削除するには、 を呼び出す必要がありますremove_filter( 'the_content', 'sharing_display', 19);。上記のコードを更新しました。

于 2013-01-15T03:37:19.467 に答える