WordPressの更新のようなTwitterを投稿する方法
-
22-10-2019 - |
質問
自分のWordPressブログでTwitterと同様の短い更新を作成できるように、プラグインやハックはありますか?
おそらく、それらの行でカスタム投稿タイプまたは何かを利用しているのでしょうか?
私が達成しようとしているのは、ブログの通常の投稿とは異なる短い(150文字制限)投稿を作成することです。これらの短い更新が公開されたら、ホームページにカスタムDivタグに表示されたいと思います。
要するに、Twitterと同じ機能ですが、ブログだけです。
ありがとう
解決
抜粋用の文字カウンターを追加するだけの場合は、この関数とJSを使用してください。
あなたのfunctions.phpのphp
// This goes in your functions.php file inside your themes folder
// Add theme support for post formats
add_theme_support( 'post-formats', array( 'aside', 'status' ) );
// Add the character counter to the admin UI
function wpse16854_char_count_script( $page )
{
$post = get_post( $_GET['post'] );
$post_type = $post->post_type;
if ( 'page' !== $post_type )
if ( 'post.php' === $page OR 'post-new.php' === $page )
wp_enqueue_script( 'excerpt-counter', get_template_directory_uri().'/excerpt-counter.js', array('jquery') );
}
add_action( 'admin_enqueue_scripts', 'wpse16854_char_count_script' );
JavaScript
// This should be saved inside a file named 'excerpt-counter.js' inside your themes folder
jQuery( document ).ready( function($)
{
$( "#excerpt" ).after( "<p style=\"text-align:center;\"><small>Excerpt length: </small><input type=\"text\" value=\"0\" maxlength=\"3\" size=\"3\" id=\"excerpt_counter\" readonly=\"\"> <small>character(s).</small></p>" );
$( "#ilc_excerpt_counter" ).val( $("#excerpt").val().length );
$( "#excerpt" ).keyup( function()
{
$( "#ilc_excerpt_counter" ).val( $("#excerpt").val().length );
} );
} );
ループ
次に、「Twitterのような」投稿を公開するときに、POSTフォーマット「ステータス」(または脇と何でも)を使用し、次のループ内に次のものを配置します。
// place the following inside your loop
if ( has_post_format( 'status' ) OR 'status' == get_post_format( $GLOBALS['post']->ID ) OR is_object_in_term( $GLOBALS['post']->ID, 'post_format', 'status' ) )
{
the_excerpt();
}
else
{
the_content(); // or however you want to treat normal posts
}
他のヒント
WordPressには、呼ばれる投稿形式があります status
これは、短いステータスの更新に使用することを目的としています。
これらの標準のポストフォーマットを使用する方法について多くの情報を見ることができます。 投稿形式のコーデックスページ
所属していません wordpress.stackexchange