WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to check if a function has content before outputting divs? (11 posts)

  1. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    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?

  2. Digital Raindrops
    Member
    Posted 3 years ago #

    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

  3. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    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!

  4. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    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

  5. esmi
    Forum Moderator
    Posted 3 years ago #

    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]

  6. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    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.....

  7. esmi
    Forum Moderator
    Posted 3 years ago #

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

  8. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    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!

  9. esmi
    Forum Moderator
    Posted 3 years ago #

    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; ?>
  10. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    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!

  11. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    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; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic