Forums

search the content for a string, and a conditional (2 posts)

  1. jaypozo
    Member
    Posted 2 years ago #

    Hi there. I'd like to either show the content, or not, based on whether a certain string is found in the content itself. This is what i have, but it's not working:

    <?php
    	$thecontent = basename(the_content(10));
    	if(strpos($thecontent, '[flickr') > 0): ?>
    		<p>Show text 1</p>
            <?php else :?>
    		<p>Show text 2</p>
    <?php endif;?>

    First off, the content gets shown on the page because of the variable assignment. Then the conditional doesn't seem to work. Any suggestions?

  2. vtxyzzy
    Member
    Posted 2 years ago #

    I don't know what the purpose of the '10' was in your sample, but the way to get the content is to get_the_content(). :)

    <?php
    	$thecontent = get_the_content('Read more ...'));
    	if(strpos($thecontent, '[flickr') > 0): ?>
    		<p>Show text 1</p>
            <?php else :?>
    		<p>Show text 2</p>
    <?php endif;?>

Topic Closed

This topic has been closed to new replies.

About this Topic