R
R
Roman Fear2021-10-21 15:54:05
WordPress
Roman Fear, 2021-10-21 15:54:05

How to display all news except the current one at the end of each post on WP?

<?php defined( 'ABSPATH' ) || exit; ?>

<?php
<style>
   h2>a
   { 
     color:black; 
   }
  </style>
<div class="su-posts su-posts-default-loop">

  <?php if ( $posts->have_posts() ) : ?>

    <?php while ( $posts->have_posts() ) : $posts->the_post(); ?>

      <div id="su-post-<?php the_ID(); ?>" class="su-post">

        <h2 class="su-post-title-custom"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
        
                 <?php
          global $more;
          $more = 1; 				 
          the_content(); ?>
        <div class="su-post-meta">
          <?php _e( 'Posted', 'shortcodes-ultimate' ); ?>: <?php the_time( get_option( 'date_format' ) ); ?>
        </div>

        <div class="su-post-excerpt">
          <?php the_excerpt(); ?>
        </div>

        <?php if ( have_comments() || comments_open() ) : ?>
          <a href="<?php comments_link(); ?>" class="su-post-comments-link"><?php comments_number( __( '0 comments', 'shortcodes-ultimate' ), __( '1 comment', 'shortcodes-ultimate' ), '% comments' ); ?></a>
        <?php endif; ?>

      </div>

    <?php endwhile; ?>

  <?php else : ?>
    <h4><?php _e( 'Posts not found', 'shortcodes-ultimate' ); ?></h4>
  <?php endif; ?>

</div>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan K, 2021-10-21
@Kypidon4ik

$currentPost = get_the_ID();
$currentPost = array($currentPost)
$query = new WP_Query( [ 'post__not_in' => $currentPost] );

while ( $query->have_posts() ) {
  $query->the_post();

  // выводим посты
}

D
Dmitry, 2021-10-21
@pro100taa

Look at this material https://wp-kama.ru/function/wp_query (pay attention to post-not-in)
Similar implementation here https://wordpress.stackexchange.com/questions/3125...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question