Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress post循环未按预期工作_Php_Wordpress_Loops_If Statement - Fatal编程技术网

Php Wordpress post循环未按预期工作

Php Wordpress post循环未按预期工作,php,wordpress,loops,if-statement,Php,Wordpress,Loops,If Statement,我使用的主题使用博客页面在博客页面上显示其所有内容,而不是摘录,然后当我点击帖子时,我想显示全部内容 我正在使用以下代码: $postId = get_the_ID(); $ex = the_excerpt(); if($postId == 19){ echo $ex; } else{ echo $content; } 博客页面位于post=19 我希望

我使用的主题使用博客页面在博客页面上显示其所有内容,而不是摘录,然后当我点击帖子时,我想显示全部内容

我正在使用以下代码:

$postId = get_the_ID();
        $ex = the_excerpt();

        if($postId == 19){

            echo $ex;


        }

        else{

            echo $content;

        }
博客页面位于post=19

我希望只有摘录显示在博客页面上,内容显示在帖子页面上。然而,两者都显示了这一点。同样,如果我在if语句中更改数字19也没关系。谁能看出我错在哪里

编辑所做的更改、屏幕截图:


函数,如
the_extract()
仅在循环内部或调用函数the_post()后可用

您可能只想在index.php中显示

while (has_posts()) {
    the_post();

    the_excerpt();
}
在single.php中,您可能希望显示整个内容

if(has_posts()) {
    the_post();

    the_content();
}

您需要使用
the_extract()表示您希望显示摘录,但如果您希望获取摘录的值但不希望直接显示,则必须使用
get_the_extract()所以您需要更改

$ex = the_excerpt(); 

to

 $ex = get_the_excerpt();
内容()的情况也是如此


希望它能对你有所帮助。

谢谢你,伙计,这在博客页面上效果很好,但是现在每个博客页面都会显示摘录和内容。你能发送截图吗?谢谢你的帮助mate@jrarama,
_content()
本身用于输出内容,因此它不需要
回显_content()。这同样适用于
摘录()
$ex = the_excerpt(); 

to

 $ex = get_the_excerpt();