Php 为什么我的WP在关闭后循环重复内容?
我已经搜索了我的代码,看看为什么我的循环会重复页面上显示的内容。我知道这与我关闭while循环有关,但我没有成功地找出问题的原因。如果有新的眼光来看看这件事,告诉我我做错了什么,我将不胜感激。提前谢谢你Php 为什么我的WP在关闭后循环重复内容?,php,html,wordpress,while-loop,custom-wordpress-pages,Php,Html,Wordpress,While Loop,Custom Wordpress Pages,我已经搜索了我的代码,看看为什么我的循环会重复页面上显示的内容。我知道这与我关闭while循环有关,但我没有成功地找出问题的原因。如果有新的眼光来看看这件事,告诉我我做错了什么,我将不胜感激。提前谢谢你 <?php /* Template Name: Blog Page Template */ ?> <?php get_header(); ?> <section class="component" role="main"> <header class=
<?php
/*
Template Name: Blog Page Template
*/
?>
<?php get_header(); ?>
<section class="component" role="main">
<header class="header">
<h1 class="entry-title">Blog</h1>
</header>
<section class="component">
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'posts_per_page' => 7,
'paged' => $paged
);
$custom_query = new WP_Query( $args );
$post_number = 0;
if ( have_posts() ) : while($custom_query->have_posts()) :
$custom_query->the_post();
$modone_qry = new WP_Query( $args );
$post_number = 0;
if ( $modone_qry->have_posts() ) : while ( $modone_qry->have_posts() ) : $modone_qry->the_post();
$post_number++;
if ($post_number === 1):
if ( has_post_thumbnail()) {
// do stuff if there is a post thumbnail
?>
<div class="recent_articles_hero" style="background: url('<?php the_post_thumbnail_url(); ?>'); background-size: cover;">
<div class="block_item_overlay"></div>
<div class="recent_articles_content">
<h4 class="section_label"><?php echo get_the_date('F j, Y'); ?></h4>
<h1><?php the_title(); ?></h1>
<a href="<?php the_permalink(); ?>" class="button_styling">
Read More
</a>
</div>
</div>
</section>
<?php } else {
// do stuff if there is not a post thumbnail
?>
<div class="recent_articles_hero default_post_preview">
<div class="block_item_overlay"></div>
<div class="recent_articles_content">
<h4 class="section_label"><?php echo get_the_date('F j, Y'); ?></h4>
<h1><?php the_title(); ?></h1>
<a href="<?php the_permalink(); ?>" class="button_styling">
Read More
</a>
</div>
</div>
</section>
<?php } ?>
<section id="articles_wrapper" class="block_items_container">
<?php else:
if ( has_post_thumbnail()) {
// do stuff if there is a post thumbnail
?>
<div class="block_item article" style="background: url('<?php the_post_thumbnail_url(); ?>'); background-size: cover; background-position: 50%;">
<div class="block_item_overlay"></div>
<h4 class="section_label"><?php echo get_the_date('F j, Y'); ?></h4>
<div class="block_item_content">
<h3><?php the_title(); ?></h3>
<p><?php echo apply_filters( 'the_content', wp_trim_words( strip_tags( $post->post_content ), 12 ) ); ?></p>
<a href="<?php the_permalink(); ?>" class="button_styling">Read More</a>
</div>
</div>
<?php } else {
// do stuff if there is not a post thumbnail
?>
<div class="block_item article default_post_preview">
<h4 class="section_label"><?php echo get_the_date('F j, Y');?></h4>
<div class="block_item_content">
<h3><?php the_title(); ?></h3>
<p><?php echo apply_filters( 'the_content', wp_trim_words( strip_tags( $post->post_content ), 12 ) ); ?></p>
<a href="<?php the_permalink(); ?>" class="button_styling">Read More</a>
</div>
</div>
<?php } ?>
<?php endif; ?>
<?php endwhile; wp_reset_query(); else : ?>
<?php endif; ?>
<div class="clear"></div>
<?php if (function_exists("pagination")) {
pagination($custom_query->max_num_pages);
} ?>
</section>
</section>
博客
重复查询,同时循环两次也会更改第一行
<?php
$paged = get_query_var( 'page' ,1 );
$args = array(
'posts_per_page' => 7,
'paged' => $paged
);
$custom_query = new WP_Query( $args );
$post_number = 0;
if ( have_posts() ) : while($custom_query->have_posts()) :
$custom_query->the_post();
if ($post_number === 1):
if ( has_post_thumbnail()) {
// do stuff if there is a post thumbnail
?>
重复查询,同时循环两次也会更改第一行
<?php
$paged = get_query_var( 'page' ,1 );
$args = array(
'posts_per_page' => 7,
'paged' => $paged
);
$custom_query = new WP_Query( $args );
$post_number = 0;
if ( have_posts() ) : while($custom_query->have_posts()) :
$custom_query->the_post();
if ($post_number === 1):
if ( has_post_thumbnail()) {
// do stuff if there is a post thumbnail
?>
感谢您的回复。如果我去掉第二个循环,我的页面将无法加载。明白了!我没有删除第二个关闭时。这是漫长的一天。。。哈哈!谢谢你的回复。如果我去掉第二个循环,我的页面将无法加载。明白了!我没有删除第二个关闭时。这是漫长的一天。。。哈哈!