Files
profile/topfreshnode-list.php
Andrey Kuvshinov 8fc8cbae32 add files
2025-07-09 21:21:17 +03:00

106 lines
3.8 KiB
PHP

<?php
/*
Template Name: Top fresh node list
*/
$ref = filter_input(INPUT_SERVER, 'HTTP_REFERER');
$isFromSF = mb_stripos($ref, 'seo-fast.ru');
$count = (int)get_option('topfreshnode_list_count');
$count = $count+1;
update_option('topfreshnode_list_count', $count);
$redirect = array();
$last = array_map(
function($post){
return $post->ID;
},
get_posts(
array(
'posts_per_page' => 100,
'post_status' => 'publish',
'post_type' => array('anew','profile_article','yellow'),
'orderby' => 'date',
'order' => 'DESC',
'date_query' => array(
array(
'after' => '24 hours ago'
)
)
)
)
);
$top = json_decode(get_option('ppp_options'));
$top = array_reduce($top, function ($result, $item) {
$item = (array)$item;
$result[$item['id']] = $item['count'];
return $result;
}, array());
arsort($top);
$top = array_keys($top);
foreach ($top as $t_item){
foreach ($last as $l_item){
if ($l_item == $t_item){
array_push($redirect, $l_item);
}
if(count($redirect) >= 5){
break;
}
}
}
?>
<?php get_header();?>
<div class="row clearfix d-block">
<div class="col-12 col-xl-9 float-left">
<div class="newslist">
<div class="newslist__result">
<?php foreach ($redirect as $post): ?>
<div class="newslist__item">
<div class="d-flex">
<?php if (has_post_thumbnail($post) && show_thumbnail($post)): ?>
<div class="newslist__frame">
<a href="<?php echo esc_url( get_permalink($post) ); ?>">
<img loading="lazy" <?php if(wp_is_mobile()): ?>src="<?= get_template_directory_uri() ?>/assets/img/Profile_lazyload_m.webp"<?php else: ?>src="<?= get_template_directory_uri() ?>/assets/img/Profile_lazyload.jpg"<?php endif; ?> class="lazyload" data-src="<?php echo get_the_post_thumbnail_url($post); ?>" alt="<?php the_title($post); ?>" />
</a>
</div>
<?php endif; ?>
<div>
<div class="newslist__body">
<h2 class="newslist__title">
<a href="<?php echo esc_url( get_permalink($post) ); ?>"><?php echo get_the_title($post); ?></a>
</h2>
</div>
<div class="publication__data">
<?php echo get_the_date("j.m.Y H:i", $post); ?>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
<div class="col-12 col-xl-3 float-left d-none d-xl-block">
<div class="right-side">
<?php dynamic_sidebar('right_sidebar'); ?></div>
<div class="js-stickybit">
<?php get_template_part( 'content', 'ad' ); ?>
</div>
</div>
</div>
</div>
<?php if($isFromSF !== false): ?>
<script>
setTimeout('location="<?php echo get_permalink($redirect[rand(0,count($redirect)-1)]); ?>"', 2000);
</script>
<?php endif; ?>
<?php get_footer(); ?>