WordPress blog, use only archive for current page?

I am creating a WP website with news and blogs.

They will be on separate pages: “One for news” and “One for blog”, which will be divided into categories.

So, for example, I have this code in the "News", which stops the cycle of receiving messages:

<?php 
    $uncat = get_cat_ID('uncategorised');
    $uncat2 = get_cat_ID('blog');

    $args = array(
      'posts_per_page' => 3,
      'category__not_in' => array($uncat, $uncat2)

      );
    $loop = new WP_Query( $args );
    while ($loop->have_posts() ) : $loop->the_post();
    ?>
    <div class="col-md-12 col-sm-12 col-xs-12" style="padding-left:0; padding-right:0;">
      <a style="color:#333; text-decoration:none;" href="<?php echo get_permalink(); ?>">
        <div class="postsize">
          <div class="leftfloat" style="float: left; padding-right:20px;">
            <?php echo get_the_post_thumbnail( $page->ID, 'categoryimage', array('class' => 'faqposts')); ?>

          </div>
          <div class="contentfaq">
            <h4><?php the_title(); ?></h3>
              <span class="entry-date-blue"><strong><?php echo get_the_date('d/m/y'); ?></strong></span>

              <?php $trimexcerpt = get_the_excerpt();

              $shortexcerpt = wp_trim_words( $trimexcerpt, $num_words = 10, $more = '… <br/> <a href="">Read More ...</a>' ); 

              echo '<a style="color:#333; text-decoration:none;" href="' . get_permalink() . '"><p>' . $shortexcerpt . '</p></a>'; 

              ?>
            </div>
          </div>
        </div>
      </a>


    <?php endwhile; ?>
    <?php wp_reset_query(); ?> 
  </div>

This works fine, but I also have “Archives” on the right side that filter by date. The problem is that it will receive messages from the News and Blog magazine, which is detrimental to the idea of ​​separating them.

Is there a way to separate them, so if a user clicks "March 2015" in the archive, he will receive messages only from this month from NEWS?

Here is my current code for Archive.php

     <?php if (have_posts()) : ?>
  <!-- First, the loop checks whether any posts were discovered with the have_posts() function. -->



  <!-- If there were any posts, a PHP while loop is started. A while loop will continue to execute as long as the condition in the parenthesis is logically true. So, as long as the function have_posts() returns a true value, the while loop will keep looping (repeating). -->
  <?php while (have_posts()) : the_post(); ?>
  <div class="col-md-12 col-sm-12 col-xs-12">
    <a href="<?php echo get_permalink(); ?>">
    <div class="postsize">
      <div style="float: left; padding-right:20px;">
        <?php echo get_the_post_thumbnail( $page->ID, 'categoryimage', array('class' => 'faqposts')); ?>

      </div>
      <h5 class="captext"><?php the_title(); ?></h5>
      <span class="entry-date-orange"><?php echo get_the_date(); ?></span>
      <?php
      foreach((get_the_category()) as $category) { 
        echo ' | ' . $category->cat_name; 
      } 
      ?>

      <p style="margin-top:10px";><?php the_excerpt(); ?></p>
    </div>
  </a>
  </div>
  <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
  <?php endif; ?>
+4
1

,

    <h2>Archives by Month:</h2>
    <ul>
        <?php wp_get_archives('type=monthly'); ?>
    </ul>

    <h2>Archives by Subject:</h2>
    <ul>
         <?php wp_list_categories(); ?>
    </ul> 

<?php
/*
  Template Name: Archives
 */
get_header(); ?>

<div id="container">
<div id="content" role="main">

 <?php the_post(); ?>
    <h1 class="entry-title"><?php the_title(); ?></h1>

    <?php get_search_form(); ?>

    <h2>Archives by Month:</h2>
    <ul>
        <?php wp_get_archives('type=monthly'); ?>
    </ul>

    <h2>Archives by Subject:</h2>
    <ul>
         <?php wp_list_categories(); ?>
    </ul>

   </div><!-- #content -->
 </div><!-- #container -->

 <?php get_sidebar(); ?>
 <?php get_footer(); ?>
0

Source: https://habr.com/ru/post/1589020/


All Articles