【问题标题】:WordPress the_content()WordPress the_content()
【发布时间】:2013-12-20 03:02:33
【问题描述】:

我一直试图弄清楚为什么这个函数 the_content() 会在我从仪表板创建的任何页面的底部显示 2 个链接。它还复制了标题,如下图所示。任何想法为什么会发生这种情况?

<?php
/*
 Template Name: Booking Template
*/

//response generation function
$response = "";

//function to generate response
function my_contact_form_generate_response($type, $message){

global $response;

if($type == "success") $response = "<div class='success'>{$message}</div>";
else $response = "<div class='error'>{$message}</div>";

 }

  //response messages
$not_human       = "Human verification incorrect.";
$missing_content = "Please supply all information.";
$email_invalid   = "Email Address Invalid.";
$message_unsent  = "Message was not sent. Try Again.";
$message_sent    = "Thanks! Your message has been sent.";

//user posted variables
$name = $_POST['message_name'];
$email = $_POST['message_email'];
$message = $_POST['message_text'];
$human = $_POST['message_human'];

//php mailer variables
$to = get_option('admin_email');
$subject = "Someone sent a message from ".get_bloginfo('name');
$headers = 'From: '. $email . "rn" .
  'Reply-To: ' . $email . "rn";

if(!$human == 0){
if($human != 2) my_contact_form_generate_response("error", $not_human); //not human!
else {

  //validate email
  if(!filter_var($email, FILTER_VALIDATE_EMAIL))
    my_contact_form_generate_response("error", $email_invalid);
  else //email is valid
  {
    //validate presence of name and message
    if(empty($name) || empty($message)){
      my_contact_form_generate_response("error", $missing_content);
    }
    else //ready to go!
    {
      $sent = wp_mail($to, $subject, strip_tags($message), $headers);
      if($sent) my_contact_form_generate_response("success", $message_sent); //message sent!
      else my_contact_form_generate_response("error", $message_unsent); //message wasn't sent
    }
  }
 }
}
else if ($_POST['submitted']) my_contact_form_generate_response("error",                           $missing_content);  

 get_header(); ?>

 <div id="content" class="<?php echo implode( ' ', responsive_get_content_classes() ); ?  >">

  <?php while ( have_posts() ) : the_post(); ?>

      <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

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

        <div class="entry-content">
          <?php the_content(); ?>

           <?php echo $response; ?>
          <form action="<?php the_permalink(); ?>" method="post">
            <p><label for="name">Name: <span>*</span> <br><input type="text" name="message_name" value="<?php echo esc_attr($_POST['message_name']); ?>"></label></p>
            <p><label for="message_email">Email: <span>*</span> <br><input type="text" name="message_email" value="<?php echo esc_attr($_POST['message_email']); ?>"></label></p>
            <p><label for="message_text">Message: <span>*</span> <br><textarea type="text" name="message_text"><?php echo esc_textarea($_POST['message_text']); ?></textarea></label></p>
            <p><label for="message_human">Human Verification: <span>*</span> <br><input type="text" style="width: 60px;" name="message_human"> + 3 = 5</label></p>
            <input type="hidden" name="submitted" value="1">
            <p><input type="submit"></p>
          </form>

        </div><!-- .entry-content -->

      </article><!-- #post -->

  <?php endwhile; // end of the loop. ?>

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

【问题讨论】:

  • 能否请您发布页面/模板代码?
  • 这里是完整的代码。我的目标是将页面模板添加到现有主题。它包含一个表单,现在是基本字段。
  • 发布你的functions.php文件,寻找the_content的过滤器

标签: wordpress wordpress-theming


【解决方案1】:

the_content 是一个过滤器,参见http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content。因此,如果我没有按预期行事,也没有默认行事,请在您的 functions.php 中查找过滤器。您将在主题文件夹中找到 functions.php。 很可能您的过滤函数会再次调用the_title() 过滤器。

链接和 URL 可能是商城格式的“阅读更多”链接的结果。见:http://codex.wordpress.org/Customizing_the_Read_More

【讨论】:

    猜你喜欢
    • 2016-03-04
    • 2019-07-06
    • 2015-05-09
    • 2012-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 2015-06-14
    相关资源
    最近更新 更多