• Resolved gbadmin

    (@asavard)


    The current code below controls what text is added as an overlay on the page banners for each custom post type (products, people, and news). I am trying to add a new statement to display custom text on one particular news post.

    Any ideas?

    <?php
    /**Displaying Custom Field Data**/
    	$featuredtext = get_post_meta( $post->ID, 'featured-text', true );
    	if( ! empty( $featuredtext ) && ! is_search() ) {
    		foreach( $featuredtext as $text)
    		{
    		    echo '<div class="banner-text"><span>'.$text['featured-image-text'].'</span></div>';
    		}
    	} elseif ($current_posttype == 'products' || is_search()) {
    				echo '<div class="banner-text"><span>' . get_option('prodFeaturedText') . '</span></div>';
    	} elseif ($current_posttype == 'people') {
    				echo '<div class="banner-text"><span>' . get_option('peopleFeaturedText') . '</span></div>';
    	} elseif ($current_posttype == 'news') {
    				echo '<div class="banner-text"><span>' . get_option('newsFeaturedText') . '</span></div>';
    	}
    ?>
Viewing 9 replies - 1 through 9 (of 9 total)
  • You should be able to use this, replacing yourpostid with the ID of the news post on which you want this specific custom text to appear.

    <?php
    /**Displaying Custom Field Data**/
    	$featuredtext = get_post_meta( $post->ID, 'featured-text', true );
    	if( ! empty( $featuredtext ) && ! is_search() ) {
    		foreach( $featuredtext as $text)
    		{
    		    echo '<div class="banner-text"><span>'.$text['featured-image-text'].'</span></div>';
    		}
    	} elseif ($current_posttype == 'products' || is_search()) {
    				echo '<div class="banner-text"><span>' . get_option('prodFeaturedText') . '</span></div>';
    	} elseif ($current_posttype == 'people') {
    				echo '<div class="banner-text"><span>' . get_option('peopleFeaturedText') . '</span></div>';
    	} elseif ($current_posttype == 'news') {
    		if ( !is_single( 'yourpostid' ) {
    			echo '<div class="banner-text"><span>' . get_option('newsFeaturedText') . '</span></div>';
    		} else {
    			echo '<div class="banner-text"><span>This is the custom text for your specific news post.</span></div>';
    		}
    	}
    ?>
    Thread Starter gbadmin

    (@asavard)

    Thank you very much for your response. After implementing that code though I got a blank white screen.

    Did you replace if ( !is_single( 'yourpostid' ) with the post id of the news post you are targeting?

    Also, if you change the debug line in your wp-config.php from define('WP_DEBUG', false); to define('WP_DEBUG', true); it may tell you what the error is.

    Thread Starter gbadmin

    (@asavard)

    Yes, I did enter the post id. Let me try finding the error.

    Thank you again. I really appreciate it.

    Thread Starter gbadmin

    (@asavard)

    It returned “Parse error: syntax error, unexpected” which points to
    if ( !is_single( '3949' ) {

    Oh, I see the problem. I missed an ending parenthesis in my code sample. Just change that line to this:

    if ( !is_single( '3949' ) ) {

    and it should work fine. Sorry about that.

    Thread Starter gbadmin

    (@asavard)

    You are awesome. Thank you so much.

    Great! Could you please mark this topic as [resolved] ? Thanks!

    Thread Starter gbadmin

    (@asavard)

    Thank you!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Conditional Statements’ is closed to new replies.