Php 在联系人表单提交后,Wordpress循环跳过else语句
我正在wordpress上创建一个相当基本的网站,包括新闻和联系人等几个部分。内容都在一个页面上 第一次加载时,页面工作正常,并正确显示所有内容。然而,一旦我通过我的联系人表单提交了一条消息,页面就会重新加载,循环不会显示任何帖子,它只会在Wordpress循环中的else语句中显示“找不到帖子” 我想知道是否有人遇到过类似的事情?我将在下班回家后粘贴代码部分,但暂时欢迎任何解决方案或可能性 循环帖子并显示在主页上的代码。这是一个外部文件,我使用php将其包含在index.php页面中Php 在联系人表单提交后,Wordpress循环跳过else语句,php,html,wordpress,loops,contact-form,Php,Html,Wordpress,Loops,Contact Form,我正在wordpress上创建一个相当基本的网站,包括新闻和联系人等几个部分。内容都在一个页面上 第一次加载时,页面工作正常,并正确显示所有内容。然而,一旦我通过我的联系人表单提交了一条消息,页面就会重新加载,循环不会显示任何帖子,它只会在Wordpress循环中的else语句中显示“找不到帖子” 我想知道是否有人遇到过类似的事情?我将在下班回家后粘贴代码部分,但暂时欢迎任何解决方案或可能性 循环帖子并显示在主页上的代码。这是一个外部文件,我使用php将其包含在index.php页面中 &l
<?php
if (have_posts()) :
query_posts('posts_per_page=3');
while (have_posts()) : the_post(); ?>
<div class="postContainerHome">
<div class="postImageHome">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('small-thumbnail'); ?></a>
</div>
<div class="postTitleHome">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
</div>
<div class="postContentHome">
<?php echo wp_trim_words(get_the_content(), 20, '...' ); ?>
</div>
<div class="readMoreButton">
<a href="<?php the_permalink(); ?>"><p class="noSelect">Read More</p></a>
</div>
</div>
<?php endwhile;
else :
echo '<p>Oops, there are no posts! Please try refreshing the page.</p>';
endif;
?>
联系人表单,也是一个外部文件,我将它包含在底部的index.php页面和单个联系人页面中
<section class="contact">
<div class="sectionSubHead">
<p class="noSelect">- Get in touch -</p>
</div>
<div class="sectionHead">
<h1 class="noSelect">Contact Us</h1>
</div>
<div class="contactFormPrompt">
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: Contact Form';
$to = 'email@address.com';
$subject = 'Message from Contact Form';
$human = $_POST['human'];
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit'] && $human == '4' && $name != '' && $email != '' && $email != '') {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
} else if ($_POST['submit'] && $human != '4') {
echo '<p>You need to fill in all required fields!</p>';
}
?>
</div>
<div class="contactFormContainer">
<form action="" method="post">
<input name="name" placeholder="Full Name*">
<input name="email" type="email" placeholder="Email*">
<textarea name="message" placeholder="Message*"></textarea>
<input name="human" placeholder="What is 2+2?* (Verification)">
<input id="submit" name="submit" type="submit" value="Send">
</form>
</div>
</section>
-联系-
联系我们
这只是我根据教程制作的一个简单的联系表单,因此它可能不是最好的,但我不确定是什么导致了问题。为了帮助您,我们肯定需要查看代码。在表单提交之前/之后查看URI模式也会很有帮助。我尝试删除我的联系人表单并添加一个非常基本的表单,但最终得到了相同的结果。所以我假设问题出在post循环的某个地方。再说一次,URI在表单提交时会变成什么?有
$\u GET
变量吗?我现在正在本地运行,所以主页就是localhost/WP。当我在主页上使用联系人表单时,它只返回相同的URI。但是,如果我使用联系人页面localhost/WP/contact-us上的联系人表单,它将返回相同的localhost/WP/contact-us,但会显示主页。没有$\u GET变量。