Reset query
-
Salve, ho creato questo codice per effettuare il troncamento personalizzato sui titoli dei post. Il codice funziona, ma il problema è che i titoli del primo widget vengono troncati a 70 caratteri, ma i successivi risultano tutti troncati di partenza a 70 quindi non riesco a troncare i titoli dell’ultimo widget con un valore superiore a 70.
Non saprei forse ho sbagliato approccio, riuscite a darmi una diritta?
Grazie per l’attenzione.function summary($content, $limit = 200) { $content = strip_tags($content); // Take the existing content and return a subset of it $end = ''; if (strlen($content) > $limit) { $end = '...'; } return substr($content, 0, $limit) . $end; } add_action( 'elementor/query/q_primopiano', function( $query ) { $meta_query = [[ 'key' => 'visibile', 'value' => '1', 'compare' => '=', ] ]; function trimTitle( $title, $id = null ) { /*return summary($title,c2c_get_custom('t_len'));*/ return summary($title,70); } $query->set('meta_query', $meta_query); $query->set('post_type', 'news'); wp_reset_postdata(); wp_reset_query(); /*$query->set('terms', 'cronaca');*/ add_filter( 'the_title', 'trimTitle', 10, 2 ); } ); /*----*/ function summary3($content, $limit = 200) { $content = strip_tags($content); // Take the existing content and return a subset of it $end = ''; if (strlen($content) > $limit) { $end = '...'; } return substr($content, 0, $limit) . $end; } add_action( 'elementor/query/q_rubrica', function( $query ) { function trimTitle2( $title, $id = null ) { return summary3($title,30); } $query->set('post_type', 'rubriche'); add_filter( 'the_title', 'trimTitle2', 10, 2 ); } ); /*----------*/ function summary4($content, $limit = 200) { $content = strip_tags($content); // Take the existing content and return a subset of it $end = ''; if (strlen($content) > $limit) { $end = '...'; } return substr($content, 0, $limit) . $end; } add_action( 'elementor/query/q_news', function( $query ) { function trimTitle3( $title, $id = null ) { return summary4($title,200); } $query->set('post_type', 'news'); add_filter( 'the_title', 'trimTitle3', 10, 2 ); } );
- Il topic ‘Reset query’ è chiuso a nuove risposte.