admin管理员组

文章数量:1319953

I have a problem.

It is <?php the_excerpt(); ?> empty from gutemberg <?php the_excerpt(); ?> pull little part of content from post but first next <?php the_permalink(); ?> under is broken and changed path from single blog to root of list of blog posts.

How to fix that?

E.g of the loop:

<?php
                  $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
                  $args = array(
                      'post_type' => 'post',
                      'posts_per_page' => 5,
                      'paged' => $paged
                  );
                  
                  $post_query = new WP_Query($args);
                  
                  if($post_query->have_posts() ) {
                      while($post_query->have_posts() ) {
                          $post_query->the_post();
                          $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'blog-thumb'); 
                          ?>
                          
               <div class="blog-item">
                  <?php if($featured_img_url) { ?>
                  <a href="<?php the_permalink(); ?>"><img src="<?php echo $featured_img_url; ?>" class="blog-thumb" id="img" alt=""></a>
                  <?php } ?>
                  <a href="<?php the_permalink(); ?>">
                     <h2 class="blog-title"><?php the_title(); ?></h2>
                  </a>
                  <?php the_excerpt(); ?>
                  <a href="<?php the_permalink(); ?> // broken link return to url/blog not url/single-blog-url" class="blog-btn">Read more</a>
               </div>
               <?php
                  }
                  }
                  ?> 

I have a problem.

It is <?php the_excerpt(); ?> empty from gutemberg <?php the_excerpt(); ?> pull little part of content from post but first next <?php the_permalink(); ?> under is broken and changed path from single blog to root of list of blog posts.

How to fix that?

E.g of the loop:

<?php
                  $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
                  $args = array(
                      'post_type' => 'post',
                      'posts_per_page' => 5,
                      'paged' => $paged
                  );
                  
                  $post_query = new WP_Query($args);
                  
                  if($post_query->have_posts() ) {
                      while($post_query->have_posts() ) {
                          $post_query->the_post();
                          $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'blog-thumb'); 
                          ?>
                          
               <div class="blog-item">
                  <?php if($featured_img_url) { ?>
                  <a href="<?php the_permalink(); ?>"><img src="<?php echo $featured_img_url; ?>" class="blog-thumb" id="img" alt=""></a>
                  <?php } ?>
                  <a href="<?php the_permalink(); ?>">
                     <h2 class="blog-title"><?php the_title(); ?></h2>
                  </a>
                  <?php the_excerpt(); ?>
                  <a href="<?php the_permalink(); ?> // broken link return to url/blog not url/single-blog-url" class="blog-btn">Read more</a>
               </div>
               <?php
                  }
                  }
                  ?> 
Share Improve this question asked Oct 16, 2020 at 13:31 Milosh N.Milosh N. 2152 silver badges8 bronze badges 1
  • Are you filtering the excerpt, e.g. via the the_excerpt hook? If so, try disabling that filter and see if it helps. – Sally CJ Commented Oct 16, 2020 at 14:47
Add a comment  | 

1 Answer 1

Reset to default 0

If it only breaks when the excerpt is empty, then I would check for the excerpt before outputting it.

<?php if ( ! empty( get_the_excerpt() ) : ?> // test for the excerpt

   <?php echo esc_html( get_the_excerpt() ); ?> // escape the excerpt in case there is html added

<?php endif; ?>

本文标签: permalinksEmpty theexcerpt() broke thepermalink() under him