为什么在我的本地环境(而在原始服务器上我没有)的 Wordpress 博客文章(仅)上收到错误消息

Why do I get an error message on Wordpress blog posts (only) on my local environment (and on the original server I don't)

我将所有 WP 文件从服务器复制到本地 WAMP 作为开发环境。 除了查看博客 post 之外,一切都运行顺利。

我得到了所有 titles/categories/post-content/ect' 的良好输出 - 但是在博客内容之前有一个奇怪的输出:

http://i.stack.imgur.com/JTKJ5.png

content.php 第 68 行是代码中的这一部分:__( ),

"the_content" 函数后一行:

<div class="post-bottom">
    <div class="post-text-container">
        <?php
            /* translators: %s: Name of current post*/
            $postURL = get_permalink();
            $commentsURL = get_comments_link();
            the_content( sprintf(
                __(  ),
                the_title( '<span class="screen-reader-text">', '</span>', false )
            ) );
            if ( !is_single() ) :
                    echo "<div class=\"read-more\"><a href=\"$postURL\">Continue reading...</a> | <a href=\"$commentsURL\">Full Comments</a></div>";
                endif;
        ?>
    </div>
</div>

这可能是什么原因造成的?

编辑:在将内容发送到我的本地服务器时我唯一改变的是:

1 - 我将我的数据库复制到本地 phpmyadmin 并在选项 table.

中将所有 http://www.example.com 更改为 http://localhost/example

2 - 我完全删除了我的 .htaccess 文件(wordpress 自己生成了一个新文件)

这是服务器上的样子:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

这是我在本地拥有的:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /example/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /example/index.php [L]
</IfModule>

# END WordPress

3- 我在 WAMP 上启用了 "rewrite_modle",因为它在默认情况下处于禁用状态。

尝试将其放入您的 wp-config.php,这并不能解决问题,但这基本上是您的服务器和本地服务器之间的区别。

error_reporting(0);

这是一个警告,您可以将其抑制,它不是错误。

要解决此问题,您需要将一个字符串传递给__() 函数,因为它需要传递一个字符串。在这里阅读更多:https://codex.wordpress.org/Function_Reference/_2

警告是关于您代码的以下部分:__( )

在WP中__实际上是一个翻译功能

简单看一下in the manual,我们可以看到__()函数的用法是:

<?php $translated_text = __( $text, $domain ); ?>

并且 $text 参数是必需的。

$text (string) (required) Text to translate. Default: None $domain

(string) (optional) Domain to retrieve the translated text. Default: 'default'

在您的代码中,您没有向该函数发送任何参数,因此您收到了合法警告。老实说,我不知道为什么一开始没有争论。此外,您的远程服务器也应该显示该警告。如果它没有 - 或者代码不同或者你在服务器上的某个地方有 error_reporting(0) (php.ini / wp-config.php).

一个简单的解决方案就是添加一个空字符串作为参数。