• Resolved Rev. Voodoo

    (@rvoodoo)


    Is there any way to check if these are empty? This whole php thing is pretty unfamiliar to me, so I’m going to keep searching…..but just in case someone can help me. I’ve got this powerpress player, and simple forum link. The classes here take up space in my layout, so I only wanted them output if there is actual content. I’m guessing that the problem here is that I’m just checking if the function exists, not if it contains anything….. is that right? Any ideas?

    <?php if(function_exists('the_powerpress_content') ) : ?>
    	<div class="powerPress">
    		<?php the_powerpress_content() ?>
    	</div>
    <?php endif; ?>
    <?php if(function_exists('sf_blog_linked_tag') ) : ?>
    	<div class="sfLink">
    		<?php sf_blog_linked_tag($post->ID, true) ?>
    	</div>
    <?php endif; ?>

    Or is it not that simple? Do I need to check something else within the plugin for content or something?

Viewing 10 replies - 1 through 10 (of 10 total)
  • As they return content you may just be able to return a conditional true if they have a value.

    <?php if(function_exists('the_powerpress_content') ) : ?>
         <?php if(the_powerpress_content() ) : ?>
    	<div class="powerPress">
    		<?php the_powerpress_content(); ?>
    	</div>
         <?php endif; ?>
    <?php endif; ?>
    <?php if(function_exists('sf_blog_linked_tag') ) : ?>
        <?php if( sf_blog_linked_tag($post->ID, true) ) : ?>
    	<div class="sfLink">
    		<?php sf_blog_linked_tag($post->ID, true); ?>
    	</div>
        <?php endif; ?>
    <?php endif; ?>

    Note: closing semi-colon’s added!
    HTH

    David

    Thread Starter Rev. Voodoo

    (@rvoodoo)

    Oh, thanks for the semis, totally missed that! I’ll have to try what you’ve got tomorrow, thanks!

    I had messed with if( !empty($post->function) ) in various manners with no success (nothing showed up at all) so I’ll play around tomorrow and report!

    Thread Starter Rev. Voodoo

    (@rvoodoo)

    Hmmm, well, I don’t believe the conditional is working? Or something is off here…. The actual link and player called by those functions works, but the div class we are adding in doesn’t print out at all

    What about trying is_plugin_active()? Failing that, you might just be targeting the wrong functions from the plugins within your conditionals.

    [NB: Still looking at that breadcrumb plugin]

    Thread Starter Rev. Voodoo

    (@rvoodoo)

    well, the plugin will always be active. I just only want those div classes output on the posts that contain those player/link items.

    And thanks again for looking into the breadcrub thing…..

    Do both of these plugins just echo content or is there a way you could feed that content into a variable?

    Thread Starter Rev. Voodoo

    (@rvoodoo)

    Yup…. I’m outta my league here…..

    add_filter('get_the_excerpt', 'powerpress_content', (POWERPRESS_CONTENT_ACTION_PRIORITY - 1) );
    add_filter('the_content', 'powerpress_content', POWERPRESS_CONTENT_ACTION_PRIORITY);
    add_filter('the_excerpt', 'powerpress_content', POWERPRESS_CONTENT_ACTION_PRIORITY);

    I’m assuming adds the player onto the content as appropriate…

    function the_powerpress_content()
    {
    	echo get_the_powerpress_content();
    }

    I’m gonna have to look at get_the_powerpress_content….

    Or…. I may just be trying to much….. Maybe I should just live with the gaps in my theme until I learn code better eh!

    It looks like get_the_powerpress_content(); could be used to drop the plugin’s output in a variable.

    <?php $my_powerpress_content = get_the_powerpress_content();
    if( isset( $my_powerpress_content) ) :?>
    	<div class="powerPress">
    		<?php the_powerpress_content(); ?>
    	</div>
         <?php endif; ?>
    <?php endif; ?>
    Thread Starter Rev. Voodoo

    (@rvoodoo)

    yup…. I had actually just done:

    <?php if(function_exists('the_powerpress_content') ) : ?>
    					<?php if(get_the_powerpress_content() ) : ?>
    						<div class="powerPress">
    							<?php the_powerpress_content(); ?>
    						</div>
    					<?php endif; ?>
    				<?php endif; ?>

    which seems to work. I’m gonna test a bit more and if that’s not it try your code. Thanks very much. I’m gonna dig into the other plugin now and see what happens.

    Much appreciated!

    Thread Starter Rev. Voodoo

    (@rvoodoo)

    Well, I absolutely can’t see anyone else ever being in this situation! lol…. but because I like closure, this appears to work for me!

    <?php if(function_exists('the_powerpress_content') ) : ?>
    					<?php if(get_the_powerpress_content() ) : ?>
    						<div class="powerPress">
    							<?php the_powerpress_content(); ?>
    						</div>
    					<?php endif; ?>
    				<?php endif; ?>
    				<?php if(function_exists('sf_blog_linked_tag') ) : ?>
    					<?php $thisLink = sf_blog_links_control('read', $post->ID);
    					if(isset( $thisLink ) ) : ?>
    						<div class="sfLink">
    							<?php sf_blog_linked_tag($post->ID, true); ?>
    						</div>
    					<?php endif; ?>
    				<?php endif; ?>

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘How to check if a function has content before outputting divs?’ is closed to new replies.