HEX
Server: Apache
System: Linux vpshost11508.publiccloud.com.br 5.15.179-grsec-vpshost-10.lc.el8.x86_64 #1 SMP Mon Apr 7 12:04:45 -03 2025 x86_64
User: wicomm2 (10002)
PHP: 8.3.0
Disabled: apache_child_terminate,dl,escapeshellarg,escapeshellcmd,exec,link,mail,openlog,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,php_check_syntax,php_strip_whitespace,popen,proc_close,proc_open,shell_exec,symlink,system
Upload Files
File: /home/wicomm2/public_html/pages/blog.php
<?php
/*
Template Name: Página do Blog
*/

get_header();

$banner_main = get_field('banner_principal');
$title = get_field('titulo');


$paged = max(1, get_query_var('paged') ? get_query_var('paged') : get_query_var('page'));

$current_category = isset($_GET['categoria']) ? sanitize_text_field($_GET['categoria']) : '';
$current_order = isset($_GET['ordem']) ? sanitize_text_field($_GET['ordem']) : 'recentes';

$order = 'DESC';
if ($current_order === 'antigos') {
  $order = 'ASC';
}

$args = array(
  'post_type' => 'post',
  'post_status' => 'publish',
  'posts_per_page' => 9,
  'paged' => $paged,
  'orderby' => 'date',
  'order' => $order,
);

if (!empty($current_category) && $current_category !== 'todas') {
  $args['category_name'] = $current_category;
}

$blog_query = new WP_Query($args);

$categories = get_categories(array(
  'taxonomy' => 'category',
  'hide_empty' => true,
));
?>

<main class="wc-blog-page">
  <div class="wc-container">

    <header class="wc-blog-page__header" style="background-image: url('<?php echo $banner_main ?>');">
      <div class="wc-home-limit__screen">
        <h1>Blog da Wicomm</h1>
        <p><?php echo $title ?></p>
      </div>
    </header>

    <div class="wc-blog-page__filters">

      <div class="wc-blog-page__categories">
        <ul class="wc-blog-page__categories-list">
          <li>
            <a href="<?php echo esc_url(add_query_arg(array(
              'categoria' => 'todas',
              'ordem' => $current_order,
              'paged' => false,
            ), get_permalink())); ?>"
              class="<?php echo (empty($current_category) || $current_category === 'todas') ? 'is-active' : ''; ?>">
              Todas
            </a>
          </li>

          <?php foreach ($categories as $category): ?>
            <li>
              <a href="<?php echo esc_url(add_query_arg(array(
                'categoria' => $category->slug,
                'ordem' => $current_order,
                'paged' => false,
              ), get_permalink())); ?>"
                class="<?php echo ($current_category === $category->slug) ? 'is-active' : ''; ?>">
                <?php echo esc_html($category->name); ?>
              </a>
            </li>
          <?php endforeach; ?>
        </ul>
      </div>

      <div class="wc-blog-page__order">
        <form method="get" action="<?php echo esc_url(get_permalink()); ?>">
          <input type="hidden" name="categoria" value="<?php echo esc_attr($current_category ?: 'todas'); ?>">

          <label for="ordem" class="screen-reader-text">Ordenar posts</label>
          <select name="ordem" id="ordem" onchange="this.form.submit()">
            <option value="recentes" <?php selected($current_order, 'recentes'); ?>>
              Mais recentes
            </option>
            <option value="antigos" <?php selected($current_order, 'antigos'); ?>>
              Mais antigos
            </option>
          </select>
        </form>
      </div>

    </div>

    <?php if ($blog_query->have_posts()): ?>
      <div class="wc-blog-page__grid">
        <?php while ($blog_query->have_posts()):
          $blog_query->the_post(); ?>
          <?php get_template_part('template-parts/components/blog-card'); ?>
        <?php endwhile; ?>
      </div>

      <?php
      $prev_link = get_previous_posts_link('Anterior', $blog_query->max_num_pages);
      $next_link = get_next_posts_link('Próximo', $blog_query->max_num_pages);
      $total_pages = (int) $blog_query->max_num_pages;
      ?>

      <?php if ($prev_link || $next_link || $total_pages > 1): ?>
        <nav class="wc-pagination" aria-label="Paginação do blog">
          <div class="wc-pagination__inner">

            <div class="wc-pagination__prev">
              <?php if ($prev_link): ?>
                <?php echo $prev_link; ?>
              <?php endif; ?>
            </div>

            <div class="wc-pagination__numbers">
              <span class="wc-pagination__status">
                Página <span><?php echo esc_html($paged); ?></span> de <span><?php echo esc_html($total_pages); ?>
                </span>
              </span>
            </div>

            <div class="wc-pagination__next">
              <?php if ($next_link): ?>
                <?php echo $next_link; ?>
              <?php endif; ?>
            </div>

          </div>
        </nav>
      <?php endif; ?>
    <?php else: ?>
      <p>Nenhum post encontrado.</p>
    <?php endif; ?>

    <?php wp_reset_postdata(); ?>

  </div>
</main>

<?php get_footer(); ?>