correct agrotop rus

This commit is contained in:
argoexpert press
2024-05-27 16:26:16 +03:00
parent 2ecc4e4089
commit f871c62628
2 changed files with 46 additions and 16 deletions

View File

@@ -39,7 +39,7 @@ $advertisers = new WP_Query([
</div> </div>
</div> </div>
</div> </div>
<a href="<?= home_url() ?>" class="articles-preview__show-next">On top</a> <a href="<?= home_url() ?>/en" class="articles-preview__show-next">On top</a>
<div class="articles__spacer-container"> <div class="articles__spacer-container">
<div class="articles__spacer"></div> <div class="articles__spacer"></div>
<div class="articles__spacer"></div> <div class="articles__spacer"></div>

View File

@@ -13,6 +13,7 @@ if (!empty($child_categories)) {
$excluded_category_ids_in = implode(',', array_map('intval', $excluded_category_ids)); $excluded_category_ids_in = implode(',', array_map('intval', $excluded_category_ids));
/**
$query = $wpdb->prepare(" $query = $wpdb->prepare("
SELECT DISTINCT p.ID, p.post_title, p.post_content, m.meta_value AS position SELECT DISTINCT p.ID, p.post_title, p.post_content, m.meta_value AS position
FROM $wpdb->posts p FROM $wpdb->posts p
@@ -25,6 +26,9 @@ $query = $wpdb->prepare("
AND tt.term_id NOT IN ($excluded_category_ids_in) AND tt.term_id NOT IN ($excluded_category_ids_in)
ORDER BY CAST(m.meta_value AS UNSIGNED) ASC ORDER BY CAST(m.meta_value AS UNSIGNED) ASC
"); ");
*/
/** /**
$query = $wpdb->prepare(" $query = $wpdb->prepare("
@@ -37,22 +41,48 @@ $query = $wpdb->prepare("
ORDER BY CAST(m.meta_value AS UNSIGNED) ASC ORDER BY CAST(m.meta_value AS UNSIGNED) ASC
");*/ ");*/
$excluded_category_id = 740;
// Запрос для получения всех постов с непустым метаполем 'top_participation_position'
$query = "
SELECT DISTINCT p.ID, p.post_title, p.post_content, m.meta_value AS position
FROM $wpdb->posts p
INNER JOIN $wpdb->postmeta m ON p.ID = m.post_id
WHERE p.post_type = 'post'
AND m.meta_key = 'top_participation_position'
AND m.meta_value != ''
ORDER BY CAST(m.meta_value AS UNSIGNED) ASC
";
$top_posts = $wpdb->get_results($query); $top_posts = $wpdb->get_results($query);
// Вывод результатов
if (!empty($top_posts)) { if (!empty($top_posts)) {
foreach ($top_posts as $post) { foreach ($top_posts as $post) {
$permalink = get_permalink($post->ID); // Проверка наличия категории или подкатегории с ID 740
$title = get_the_title($post->ID); $terms = wp_get_post_terms($post->ID, 'category');
?> $exclude = false;
<div class="most-read__link"> foreach ($terms as $term) {
<a href="<?php echo esc_url($permalink); ?>" class="most-read__link-inner text-13 link-icon-after"> if ($term->term_id == $excluded_category_id || $term->parent == $excluded_category_id) {
<?php echo esc_html($title); ?> $exclude = true;
</a> break;
</div> }
<?php }
if (!$exclude) {
$permalink = get_permalink($post->ID);
$title = get_the_title($post->ID);?>
<div class="most-read__link">
<a href="<?php echo esc_url($permalink); ?>" class="most-read__link-inner text-13 link-icon-after">
<?php echo esc_html($title); ?>
</a>
</div>
<?}
} }
} else {
echo '<p>Нет просмотренных постов.</p>';
} }?>
?>