为什么我在本地环境(仅在原始服务器上)上的Wordpress博客帖子上收到错误消息?

为什么我在本地环境(仅在原始服务器上)上的Wordpress博客帖子上收到错误消息?

问题描述:

I copied all my WP files from the server to my local WAMP as a dev-environment. Everything works smoothly except when viewing a blog post.

I get a good output of all the titles/categories/post-content/ect' - But with a strange output before the blogs content:

http://i.stack.imgur.com/JTKJ5.png <code>enter image description here</code>

content.php Line 68 is this part in the code: __( ),

One line after "the_content" function:

<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>

What can be the cause of this?

Edit: the only things that I changed when coping stuff to my local server were:

1 - I copied my database to my local phpmyadmin and changed all http://www.example.com to http://localhost/example in the options table.

2 - I totally removed my .htaccess file (and wordpress generated a new one by it self)

This is how the one on the server looks:

# 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

and this is what I have locally:

# 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- I enabled "rewrite_modle" on WAMP because it's disabled by default.

The warning is regarding the following part of your code: __( ).

In WP __ is actually a function for translation purposes.

From a short look in the manual, we can see that the __() function usage is:

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

And that the $text parameter is required.

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

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

In your code, you don't send any argument to that function and therefore you're getting a legit warning. To be honest, I don't know why there was no argument in the first place. Moreover, also your remote server should show that warning. In case it doesn't - or the code is different or you have error_reporting(0) somewhere on the server (php.ini / wp-config.php).

A simple solution would be just to add an empty string as an argument.

Try putting this in your wp-config.php, this doesn't solve the issue but this is basically the difference between your server and your local.

error_reporting(0);

It's a warning and you can suppress it, its not an error.

To solve the issue, you will need to pass a string to__() function because it expects a string to be passed. Read more here: https://codex.wordpress.org/Function_Reference/_2