From c57012212cf6ffc3ef8f4a929d8424021196d8b8 Mon Sep 17 00:00:00 2001 From: ulaulaman Date: Fri, 16 Apr 2021 11:46:16 +0200 Subject: [PATCH] Spacchettato speciali.php in tre file. Aggiunto un else di controllo in griglia.php --- speciali/griglia.php | 64 +++++++++++++++++++++++++++++++++++++++++++ speciali/speciali.php | 27 ++++++++++++++++++ speciali/tabella.php | 52 +++++++++++++++++++++++++++++++++++ 3 files changed, 143 insertions(+) create mode 100644 speciali/griglia.php create mode 100644 speciali/speciali.php create mode 100644 speciali/tabella.php diff --git a/speciali/griglia.php b/speciali/griglia.php new file mode 100644 index 0000000..682407b --- /dev/null +++ b/speciali/griglia.php @@ -0,0 +1,64 @@ + null, + 'tipo' => null, + ), + $atts + ) + ); + + if ( $tipo == null ) { + $q = new WP_Query( array( 'speciali' => $speciale, 'post_type'=> 'post', 'posts_per_page'=>-1 ) ); + } else { + $q = new WP_Query( array( 'speciali' => $speciale, 'post_type'=> $tipo, 'posts_per_page'=>-1 ) ); + $contentblu ='
'; + } + + if ( $q->have_posts() ) { + while ( $q->have_posts() ) { + $q->the_post(); + $titolo = get_the_title(); + + if ( $tipo == 'post' ) { + if ( function_exists( 'get_coauthors' ) ) { + $autori = coauthors_posts_links(", ", " e ", null, null, false); + } else { + $autori = the_author(); + } + } else { + $autori = null; + } + + if ( $autori <> null ) { + $auth = 'di '.$autori.'
'; + } else { + $auth = null; + } + + $estratto = get_the_excerpt(); + + /* griglia con titolo ed estratto: stilizzazione minimale */ + $header = '

'.$titolo.'

'; + + /* griglia con titolo ed estratto: formato tabella */ + $headerblu = '
'.$titolo.'
'; + $contentblu .= $headerblu.'
'.$auth.$estratto.'
(continua)
'; + } + + $contentblu = $contentblu.'
'; + + /* ripristino */ + wp_reset_postdata(); + } else { + $contentblu = null; + } + + return $contentblu; +} +add_shortcode( 'grigliaspeciali', 'grigliaspeciali' ); diff --git a/speciali/speciali.php b/speciali/speciali.php new file mode 100644 index 0000000..b77bc77 --- /dev/null +++ b/speciali/speciali.php @@ -0,0 +1,27 @@ + _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', + array('post','astrodidattica'), /* per estendere array('post','page','custom-post-type') */ + array( + 'hierarchical' => true, + 'labels' => $labels, + 'show_ui' => true, + 'query_var' => true, + 'rewrite' => array('slug' => 'speciali'), + ) + ); +} +add_action('init', 'speciali_tax', 0); \ No newline at end of file diff --git a/speciali/tabella.php b/speciali/tabella.php new file mode 100644 index 0000000..48ee650 --- /dev/null +++ b/speciali/tabella.php @@ -0,0 +1,52 @@ + 'null', + ), + $atts + ) + ); + + #tutti i termini associati all'eventuale speciale associato al post + $terms = get_the_terms ( $post->ID, 'speciali' ); + + foreach ( $terms as $term ) { + $term_link = get_term_link( $term, 'speciali' ); + $toc = $term->slug; + + if ( $toc <> $speciale ) { + $content = null; + } else { + $q = new WP_Query( array( 'speciali' => $speciale, 'posts_per_page'=>-1 ) ); + $header = '

Gli articoli dello speciale '.$term->name.'

'; + + if ( $q->have_posts() ) { + while ( $q->have_posts() ) { + $q->the_post(); + $titolo = get_the_title(); + + $content .= '
  • '.$titolo.'
  • '; + } + /* ripristino */ + wp_reset_postdata(); + } + $content = '
    '.$header.'
    '; + } + } + + $content = $content.$after_widget; + + if ( get_post_type() == 'post' ) { + $out = $content; + } else { + $out = null; + } + + return $out; +} +add_shortcode( 'tabspeciali', 'tabspeciali' );