0

So I've written a function to handle excerpts but just for the front page.

http://stevefleming.co.uk/

And the function is...

function excerpt_filter2($limit) {

$content = get_the_content();
$content = preg_replace("/<img[^>]+\>/i", "", $content);
$excerpt = explode(' ', $content, $limit);
if (count($excerpt)>=$limit) {
    array_pop($excerpt);
    $excerpt = implode(" ",$excerpt) . "...&nbsp;<a href='". get_permalink(the_ID()) ."'> continue reading</a>";
} else {
    $excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
echo $excerpt;
}

The problem, as you can see on the front page, is that it keeps appending the post id to the front of the text.

I've tried to debug the code and dumped the $excerpt array just before the implode is called to check that the id wasn't somehow being placed in the array... it wasn't.

I'm at a loss as to how the post id is getting there.

Any ideas?

Steve

4

2 回答 2

2

The function the_ID() automatically outputs the result. Change this line:

$excerpt = implode(" ",$excerpt) . "...&nbsp;<a href='". get_permalink(the_ID()) ."'> continue reading</a>";

To:

$excerpt = implode(" ",$excerpt) . "...&nbsp;<a href='". get_permalink(get_the_ID()) ."'> continue reading</a>";

Check out the codex for more info, Wordpress usually has an alternate function that won't output the result in the form: get_*.

于 2013-02-05T07:59:51.457 回答
0

你的代码在这里

$excerpt = implode(" ",$excerpt) . "...&nbsp;<a href='". get_permalink(the_ID()) ."'> continue reading</a>";

您正在使用

the_ID()

这将与帖子的 ID 一致,因此请尝试将其更改为

get_the_ID()

希望这就是你所面临的。:) 干杯

于 2013-02-05T08:02:14.173 回答