I guess you’d have to catch the $post->post_content, then tests which display you want and replace the <!–more> tag if needed with a str_replace. Something like:
$myposts = get_posts();
foreach ($mypost as $post):
if ($test_register_user)
str_replace ("<!--more-->","",$post->post_content);
the_content();
endforeach;
Thread Starter
jakemc
(@jakemc)
Thanks alakhnor, but that doesn’t quite work
If I replace the_content() in my theme with alt_the_content() and define:
function alt_the_content () {
global $post;
str_replace("<!--more-->","THIS IS WHERE THE MORE LINK IS",$post->post_content);
the_content();
}
… the_content() still carries on as normal and strips out the <!–more–>. I can replace <!–more–> if I use $post->post_content but then have to echo $post->post_content and lose all HTML formatting.
Any more ideas (and I’d still rather use a filter so I can leave the_content() be in my theme…)?
Thread Starter
jakemc
(@jakemc)
Sorry that should be:
function alt_the_content () {
global $post;
$post->post_content = str_replace("<!--more-->","MORE LINK",$post->post_content);
echo $post->post_content;
}
This replaces the <!–more–> but removes all formatting.
function alt_the_content () {
global $post;
$post->post_content = str_replace("<!--more-->","MORE LINK",$post->post_content);
the_content();
}
This displays the_content() as normal and doesn’t seem to replace the <!–more–>
Incidentally, I want to replace <!–more–> *and all the text that comes after*. Should I use preg_replace or is there a more elegant way to do this?
Thanks again.
Try using $page instead of $post->post_content in the str_replace.
Thread Starter
jakemc
(@jakemc)
Thanks alakhnor.
Do you mean:
function alt_the_content () {
global $post;
$page = str_replace("<!--more-->","MORE LINK",$page);
the_content();
}
?
Same result 🙁
Any more suggestions? Even some documentation about how the_content() is processed might be helpful…
Thread Starter
jakemc
(@jakemc)
I’ve found this which seems to do exactly what I need:
http://www.ayanev.com/marketingtrick-release-10-887/
Thanks anyway!