You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
5.0 KiB
PHP

<?php
/*
Template Name: Trasmissione
Template Post Type: post, page, broadcast
*/
?>
<?php
function create_onair_banner() {
$week = ["Luned&igrave","Marted&igrave","Mercoled&igrave","Gioved&igrave","Venerd&igrave","Sabato","Domenica"];
$content = $day = $cadence = $start_time = "";
$day = get_post_meta(get_the_ID(), 'on_air_day_0', true);
if (empty($day)) {
$content .= '<p style="color:#0bfafa">---> Trasmissione conclusa <---</p>';
} else {
$x = 0;
do {
$start_time = get_post_meta(get_the_ID(), 'on_air_start_'.$x, true);
$cadence = get_post_meta(get_the_ID(), 'on_air_cadence_'.$x, true);
$litteral_day = $week[((int)$day) - 1];
switch((int) $cadence) {
case 2: //ogni 2 settimane
case 3: //ogni 3 settimane
case 4: //ogni 4 settimane
$text = "$cadence $litteral_day";
break;
case 5: //una volta al mese
$start_date = get_post_meta(get_the_ID(), 'on_air_start_date_'.$x, true);
$day_of_the_month = which_day_of_the_month(new DateTime($start_date));
$text = "{$day_of_the_month}a $litteral_day del mese";
break;
default: //settimanale e altro non gestito (errori, etc.)
$text = "$litteral_day";
break;
}
$content .= '<p style="color:#0bfafa">---> In diretta ogni '.$text.' dalle ore '.$start_time.' <---</p>';
$x = $x + 1;
$day = get_post_meta(get_the_ID(), 'on_air_day_'.$x, true);
} while (!empty($day));
}
return $content;
}
get_header();?>
<main>
<div class="container">
<div class="row">
<div id="primary" class="content-area col-md-9">
<?php
while (have_posts()) :
the_post();
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php the_title('<h1 class="entry-title">', '</h1>'); ?>
</header><!-- .entry-header -->
<div class="entry-content">
<figure style="margin-bottom:2em; width:45%; padding:1em; float:right">
<?php echo get_the_post_thumbnail(get_the_ID(), 'full'); ?>
</figure>
<?php the_content(); ?>
<div class="on-air">
<?php /*Se $onair[0] non è valorizzato la trasmissione non ha diretta e quindi è conclusa */ ?>
<?php echo create_onair_banner(); ?>
</div>
<br>
<!-- Link all'archivio delle puntate -->
<?php
$category_id = get_post_meta(get_the_ID(), 'taxonomy_id', true);
$category_link = get_category_link( $category_id );
?>
<h6><a style="color:gold" href="<?php echo $category_link; ?>">[ Tutte le puntate ]</h6></a>
</div><!-- .entry-content -->
</article><!-- #post-<?php the_ID(); ?> -->
<div class="related-posts">
<h2>Ultime puntate e notizie</h2>
<?php
$cat_id = get_post_meta(get_the_ID(), 'taxonomy_id', true);
$last_posts = get_posts(
array(
'numberposts' => 3,
'category' => $cat_id
)
);
foreach ($last_posts as $s_post) {
$american_data = explode(" ", $s_post->post_date);
$data_a = explode("-", $american_data[0]); ?>
<article>
<h3>
<a href="<?php echo get_permalink($s_post->ID); ?>" title="<?php echo $s_post->post_title; ?>"><?php echo $s_post->post_title; ?></a>
</h3>
<p class="data"><?php echo $data_a[2]."/".$data_a[1]."/".$data_a[0]; ?></p>
<?php echo get_the_post_thumbnail($s_post->ID, 'full'); ?>
<p class="content"><?php echo $s_post->post_content; ?></p>
</article>
<?php
}
// If comments are open or we have at least one comment, load up the comment template.
if (comments_open() || get_comments_number()) :
comments_template();
endif;
endwhile; // End of the loop.
?>
</div>
</div><!-- #primary -->
<!-- ho commentato questo perche' visualizzava male la sidebar <div id="secondary" class="col-md-3" role="complementary"> -->
<?php get_sidebar(); ?>
<!--</div><-->
</div><!-- .wrap -->
</div>
</main>
<?php
get_footer();