mirror of
https://github.com/ulaulaman/eduinaf.git
synced 2025-06-06 00:49:14 +02:00
Widget che permette di inserire shortcode nella sidebar
This commit is contained in:
57
incl/widgets.php
Normal file
57
incl/widgets.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
#
|
||||
# widget per gli shortcode
|
||||
#
|
||||
class Widget_Shortcode extends WP_Widget {
|
||||
|
||||
/** Registrazione del widget */
|
||||
public function __construct() {
|
||||
parent::__construct(
|
||||
'widget_shortcode', // Base ID
|
||||
'Widget Shortcode', // Name
|
||||
array( 'description' => __( 'Widget per l\'inserimento degli shortcode nelle sidebar', 'text_domain' ), ) // Args
|
||||
);
|
||||
}
|
||||
|
||||
/** Back-end del widget */
|
||||
public function form( $instance ) {
|
||||
if ( isset( $instance[ 'title' ] ) ) {
|
||||
$title = $instance[ 'title' ];
|
||||
} else {
|
||||
$title = __( 'blog-post-coauthors', 'text_domain' );
|
||||
}
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo $this->get_field_name( 'title' ); ?>"><?php _e( 'Codice shortcode:' ); ?></label>
|
||||
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
|
||||
/** Ripulisce i valori del widget man mano che vengono salvati */
|
||||
public function update( $new_instance, $old_instance ) {
|
||||
$instance = array();
|
||||
$instance['title'] = ( !empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/** Front-end del widget */
|
||||
public function widget( $args, $instance ) {
|
||||
$title = apply_filters( 'widget_title', $instance['title'] );
|
||||
extract( $args );
|
||||
$shortcode = do_shortcode('['.$title.']');
|
||||
echo $shortcode;
|
||||
echo $after_widget;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// class Widget_Shortcode
|
||||
|
||||
// Registra Widget_Shortcode
|
||||
add_action( 'widgets_init', 'register_wdshortcode' );
|
||||
|
||||
function register_wdshortcode() {
|
||||
register_widget( 'Widget_Shortcode' );
|
||||
}
|
@@ -15,7 +15,7 @@ add_shortcode( 'rodari2021', function () {
|
||||
$beni = '<a href="http://www.beniculturali.inaf.it/eventi/universi-da-ascoltare/" target="inaf">Universi da ascoltare</a><br/>';
|
||||
$libri = '<a href="https://www.beniculturali.inaf.it/eventi/libri-di-astronomia-per-bambini-e-ragazzi-2020/" target="inaf">Libri di astronomia per bambini e ragazzi (2020)</a><br/>';
|
||||
$prisma = '<a href="http://www.prisma.inaf.it/" target="inaf">Progetto PRISMA</a><br/>';
|
||||
$spazio = '<a href="https://sorvegliatispaziali.inaf.it/" target="inaf">Sorvegliati spaziali</a>';
|
||||
$spazio = '<a href="https://sorvegliatispaziali.inaf.it/" target="inaf">Sorvegliati Spaziali</a>';
|
||||
|
||||
$pagine = '<div align="center" style="padding-top:40px;"><h3>Pagine correlate</h3><strong>Per i piccoli</strong><br/>'.$beni.$libri.'<strong>Per tutti</strong><br/>'.$prisma.$spazio.'</div>';
|
||||
|
||||
|
Reference in New Issue
Block a user