Come post su Twitter, come gli aggiornamenti su Wordpress
-
22-10-2019 - |
Domanda
C'è un plugin o un tale hack che posso fare brevi aggiornamenti simile a Twitter di sul mio blog wordpress?
Forse facendo uso di un tipo di messaggio personalizzato o qualcosa su queste linee?
Quello che sto cercando di realizzare è quello di creare a breve (limite di 150 caratteri) messaggi diversi ai post regolari sul blog. Una volta che questi brevi aggiornamenti sono pubblicati, mi piacerebbe che appaiono in un div personalizzato tag nella home page.
In breve, stessa funzionalità Twitter, ma solo sul tuo blog.
Grazie
Soluzione
Se si desidera aggiungere un contatore di caratteri per il vostro estratto, utilizzare questa funzione e js.
Il PHP per il vostro functions.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' );
La 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 );
} );
} );
The Loop
Poi basta usare lo "status" post formato (o parte o qualsiasi altra cosa) quando la pubblicazione di un "Twitter come" post e inserire il seguente all'interno del vostro ciclo:
// 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
}
Altri suggerimenti