Files
vij/single-3.php

167 lines
5.5 KiB
PHP
Raw Permalink Normal View History

2021-11-21 13:14:07 +03:00
<?php
2024-08-17 11:40:38 +03:00
// Включить отображение всех типов ошибок
//ini_set('display_errors', 1);
//ini_set('display_startup_errors', 1);
//error_reporting(E_ALL);
2021-11-21 13:14:07 +03:00
require TEMPLATEPATH.'/helpers/number_title.php';
get_header();?>
<div id="content">
<?//while(have_posts()):?>
<?the_post();?>
<?php $category = get_the_category();
$category_id = $category[0]->term_id;
$category_link = get_category_link($category_id);
$post_id = get_the_ID();
?>
<ul id="nav_content">
<li><a href="<?=get_site_url()?>">Главная</li>
<li>-<li>
<li><a href="<?=$category_link?>"><?=$category['0']->name;?></a></li>
<li>-<li>
<li><?=mb_substr(get_the_title(), 0, 50);?>...</li>
</ul>
2025-09-03 00:00:47 +03:00
<?$curr_number = number_info(get_the_title(), $post_id);?>
2021-11-21 13:14:07 +03:00
<h1 class="post-h1">Федеральное отраслевое издание «Ветеринария и жизнь»</h1>
<div class="current-number">
<?if ( has_post_thumbnail() ) :?>
<div class="number-img">
<img class="img-fluid rounded" src="<?php echo get_the_post_thumbnail_url(null, 'full');?>" alt="<?the_title();?>">
</div>
<div class="number_title">
<div class="number_number"><?the_title()?></div>
2021-11-21 22:00:02 +03:00
<?if (isset($curr_number['guid'])):?>
2021-11-21 13:14:07 +03:00
<div>
2021-11-21 22:00:02 +03:00
<a href="<?=$curr_number['guid']?>" class="orange_button" target="_blank">Читать PDF версию</a>
2021-11-21 13:14:07 +03:00
</div>
<?endif?>
</div>
<?endif?>
2026-02-07 11:05:31 +03:00
</div>
2021-12-18 01:25:19 +03:00
2026-02-07 11:05:31 +03:00
<?php
// Обработка ошибки в функции get_posts() с тегом
try {
$posts = get_posts([
'tag' => 'номер'.$curr_number['number'],
'post_type' => 'post',
'numberposts' => -1
]);
} catch (Exception $e) {
// Логируем ошибку и используем альтернативный подход
error_log('Error in get_posts with tag: ' . $e->getMessage());
// Альтернативный способ получения постов по тегу
$tag = get_term_by('name', 'номер'.$curr_number['number'], 'post_tag');
if ($tag) {
$posts = get_posts([
'tag_id' => $tag->term_id,
'post_type' => 'post',
2021-12-24 17:17:53 +03:00
'numberposts' => -1
2021-12-18 01:25:19 +03:00
]);
2026-02-07 11:05:31 +03:00
} else {
$posts = [];
}
}
2021-12-18 01:25:19 +03:00
2026-02-07 11:05:31 +03:00
$pitems = [];
$endpolosa = 1;
2024-08-17 11:40:38 +03:00
2026-02-07 11:05:31 +03:00
if (!empty($posts)) {
foreach ($posts as $post) {
$posttags = get_the_tags($post->ID);
if ($posttags) {
foreach ($posttags as $tag) {
$pfind = strpos($tag->name, 'полоса');
2024-08-17 11:40:38 +03:00
2026-02-07 11:05:31 +03:00
if ($pfind !== false) {
$number = (int)substr($tag->name, 0, $pfind);
if ($number > $endpolosa) {
$endpolosa = $number;
2021-12-18 01:25:19 +03:00
}
2026-02-07 11:05:31 +03:00
$pitems[$number][] = $post;
2021-12-18 01:25:19 +03:00
}
}
2026-02-07 11:05:31 +03:00
}
}
?>
<?php for ($i = 1; $i <= $endpolosa; $i++) { ?>
<?php if (isset($pitems[$i])): ?>
<!--<h2 class="part_title">Полоса <?php echo $i; ?></h2>-->
<?php foreach($pitems[$i] as $item): ?>
<?php
$category = get_the_category($item->ID);
$category_id = $category[0]->term_id;
$category_link = get_category_link($category_id);
?>
<div class="main-card">
<?php if (has_post_thumbnail($item->ID)) : ?>
<div class="polosa-img">
<a href="<?php the_permalink($item->ID); ?>">
<img src="<?php echo get_the_post_thumbnail_url($item->ID, 'large'); ?>" alt="<?php echo esc_attr($item->post_title); ?>">
</a>
2021-12-18 01:25:19 +03:00
</div>
2026-02-07 11:05:31 +03:00
<?php endif; ?>
<br>
<div class="main-card-title">
<p>
<a href="<?php the_permalink($item->ID); ?>">
<?php echo get_the_title($item->ID); ?>
</a>
</p>
</div>
<div class="main-card-body">
<div>
<a href="<?php the_permalink($item->ID); ?>">
<?php echo $item->post_excerpt; ?>
</a>
</div>
<br>
<div class="news_date">
<a href="<?php echo $category_link; ?>">
<?php echo $category[0]->name; ?>
</a>
</div>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
<?php }
} ?>
2021-11-21 13:14:07 +03:00
2026-02-07 11:05:31 +03:00
<?php
$numbers_year = date('Y');
include get_template_directory().'/blocks/arh_more.php';
?>
<div class="publ-to-main">
<button class="more_button" onclick="location.href='<?php echo get_site_url(); ?>/category/arkhiv'" type="button">
Архив номеров
</button>
</div>
2021-11-21 13:14:07 +03:00
</div>
<?php get_footer();?>