Wordpress the_content <! - more - > issue?

时间:2011-10-27 23:57:38

标签: php wordpress

我正在使用一个函数来决定文章的长度(下图)。问题是,在我的索引页面上,the_content似乎被我的<!-- more -->标签“拆分”了。

例如,我的文章长度为3000个字符,但在“阅读更多”链接出现之前,我的索引页只显示500个字符。我的函数使用500个字符作为the_content而不是实际的3000个字符。长度显示为,即使完整文章被视为

但是在完整的文章页面中,显示了所有3000个字符,该功能正常。

现在我的问题是:是否有替代the_content,总是使用完整的文章而不是页面上当前显示的内容?

function wcount(){
ob_start();
the_content();
$content = ob_get_clean();
$length = strlen($content);
if ($length > 2000) { 
        return 'Long'; 

    } else if ($length > 1000) { 
        return 'Medium'; 

    } else if ($length <  1000) { 
        return 'Short'; 
    }
}

2 个答案:

答案 0 :(得分:1)

试试这个:

function wcount($post) {
    $length = strlen($post->post_content);
    if ($length > 2000) { 
            return 'Long'; 

        } else if ($length > 1000) { 
            return 'Medium'; 

        } else if ($length <  1000) { 
            return 'Short'; 
        }
}

然后使用echo wcount($post);

之类的内容在post循环中调用wcount()

答案 1 :(得分:0)

尝试     全球$ more;        $ more = 0;        the_content();