I am very new to PHP and really don’t know where to start when it comes to writing it myself.
I have found this function for WordPress which I am using:
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'<a href="<?php the_permalink(); ?>">Read In Full</a>';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`[[^]]*]`','',$excerpt);
return $excerpt;
}
function content($limit) {
$content = explode(' ', get_the_content(), $limit);
if (count($content)>=$limit) {
array_pop($content);
$content = implode(" ",$content).'[...]';
} else {
$content = implode(" ",$content);
}
$content = preg_replace('/[.+]/','', $content);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return $content;
}
In the above code, I have placed
"<?php the_permalink(); ?>"
into the href. It is just showing up as a string of words instead of creating a call to the posts link.
Anyone help me out??
Thanks!
I was having this exact problem, and found that sbrajesh was right â we need to use
get_permalink()
. But it only works if you append the php properly â when I used<?php ?>
it didn’t process the php at all (just spit out the html).Here is the working version I ended up with:
echo implode(' ', $words)."<span class='more'><a href='" . get_permalink() . "'>read more</a></span>"; }
Try it like this:
You forgot to put ‘ before and after php. Hope this helps you.
Later edit:
I guess your whole code is write in php. Then I think you should try:
Hope this time will work.