2018-03-23 23:33:38 +01:00
< ? php
# tassonomia per gli speciali
function speciali_tax () {
$labels = array (
'name' => _x ( 'Speciali' , 'taxonomy general name' ),
'singular_name' => _x ( 'Speciale' , 'taxonomy singular name' ),
'all_items' => __ ( 'Tutti gli speciali' ),
'edit_item' => __ ( 'Modifica speciale' ),
'update_item' => __ ( 'Aggiorna speciale' ),
'add_new_item' => __ ( 'Aggiungi un nuovo speciale' ),
'new_item_name' => __ ( 'Nuovo speciale' ),
'menu_name' => __ ( 'Speciali' ),
);
register_taxonomy (
'speciali' ,
2020-07-28 09:23:18 +02:00
array ( 'post' , 'astrodidattica' ), /* per estendere array('post','page','custom-post-type') */
2018-03-23 23:33:38 +01:00
array (
'hierarchical' => true ,
'labels' => $labels ,
'show_ui' => true ,
'query_var' => true ,
'rewrite' => array ( 'slug' => 'speciali' ),
)
);
}
add_action ( 'init' , 'speciali_tax' , 0 );
2018-03-28 02:20:59 +02:00
# shortcode per la creazione della griglia per la pagina degli speciali
function grigliaspeciali ( $atts ) {
2018-03-23 23:51:40 +01:00
global $post ;
extract (
shortcode_atts (
array (
'speciale' => 'null' ,
),
$atts
)
);
2020-09-07 12:32:10 +02:00
$q = new WP_Query ( array ( 'speciali' => $speciale , 'post_type' => 'post' , 'posts_per_page' =>- 1 ) );
2020-08-24 11:59:18 +02:00
$contentblu = '<div class="divTable paleBlueRows">' ;
2018-03-23 23:51:40 +01:00
if ( $q -> have_posts () ) {
while ( $q -> have_posts () ) {
$q -> the_post ();
$titolo = get_the_title ();
2018-03-28 02:20:59 +02:00
if ( function_exists ( 'get_coauthors' ) ) {
$autori = coauthors_posts_links ( " , " , " e " , null , null , false );
} else { $autori = the_author ();}
$estratto = get_the_excerpt ();
2020-08-24 11:44:33 +02:00
/* griglia con titolo ed estratto: stilizzazione minimale */
2020-08-24 11:28:23 +02:00
$header = '<h4 style="color: #ecb252;">' . $titolo . '</h4>' ;
2020-08-24 11:44:33 +02:00
/* griglia con titolo ed estratto: formato tabella */
2020-08-24 11:28:23 +02:00
$headerblu = '<div class="divTableHeading"><div class="divTableRow"><div class="divTableHead">' . $titolo . '</div></div></div>' ;
2020-08-24 11:59:18 +02:00
$contentblu .= $headerblu . '<div class="divTableBody"><div class="divTableRow"><div class="divTableCell"><em>di <strong>' . $autori . '</strong></em><br/>' . $estratto . '<br/>(<a href="' . get_the_permalink () . '" style="color: #1d71b8;">continua</a>)</div></div></div>' ;
2018-03-23 23:51:40 +01:00
}
2018-03-28 02:20:59 +02:00
2020-08-24 11:59:18 +02:00
$contentblu = $contentblu . '</div>' ;
2020-08-24 11:28:23 +02:00
2018-03-23 23:51:40 +01:00
/* ripristino */
wp_reset_postdata ();
2018-03-23 23:33:38 +01:00
}
2018-03-23 23:51:40 +01:00
2020-08-24 11:28:23 +02:00
return $contentblu ;
2018-03-23 23:33:38 +01:00
}
2018-03-28 02:20:59 +02:00
add_shortcode ( 'grigliaspeciali' , 'grigliaspeciali' );
2018-03-23 23:33:38 +01:00
2018-03-28 02:20:59 +02:00
#shortcode per mostrare in una tabella l'elenco degli articoli di uno speciale: da utilizzare in un widget di testo in attesa di creare un widget vero e proprio
function specialishort ( $atts ) {
2018-03-23 23:51:40 +01:00
global $post ;
extract (
shortcode_atts (
array (
'speciale' => 'null' ,
),
$atts
)
);
2018-03-28 02:20:59 +02:00
#tutti i termini associati all'eventuale speciale associato al post
$term_list = wp_get_post_terms ( $post -> ID , 'speciali' , array ( " fields " => " all " ));
#estrazione del nome dello speciale associato al post
$nomespeciale = $term_list [ 0 ] -> name ;
2018-03-23 23:51:40 +01:00
2018-03-28 02:20:59 +02:00
if ( $nomespeciale <> $speciale ) { $content = null ; } else {
$q = new WP_Query ( array ( 'speciali' => $speciale , 'posts_per_page' =>- 1 ) );
2018-05-03 10:21:01 +02:00
$header = '<div class="divTable paleBlueRows"><div class="divTableHeading"><div class="divTableRow"><div class="divTableHead"><strong>Speciale ' . $speciale . '</strong></div></div></div>' ;
2018-03-23 23:51:40 +01:00
2018-03-28 02:20:59 +02:00
if ( $q -> have_posts () ) {
while ( $q -> have_posts () ) {
$q -> the_post ();
$titolo = get_the_title ();
if ( function_exists ( 'get_coauthors' ) ) {
$autori = coauthors_posts_links ( " , " , " e " , null , null , false );
} else {
$autori = the_author ();
}
$estratto = get_the_excerpt ();
2018-05-03 10:21:01 +02:00
$content .= '<div class="divTableBody"><div class="divTableRow"><div class="divTableCell"><a href="' . get_the_permalink () . '" style="color: #1d71b8;">' . $titolo . '</a></div></div></div>' ;
2018-03-28 02:20:59 +02:00
}
/* ripristino */
wp_reset_postdata ();
}
2018-03-23 23:33:38 +01:00
}
2018-03-23 23:51:40 +01:00
2018-05-03 10:21:01 +02:00
$content = '<p>' . $header . $content . '</div></p>' ;
2018-03-23 23:51:40 +01:00
return $content ;
2018-03-23 23:33:38 +01:00
}
2018-03-28 02:20:59 +02:00
add_shortcode ( 'specialishort' , 'specialishort' );