• Resolved TrishaM

    (@trisham)


    I love this Theme but need to make what seems like it should be a minor revision but I’m having some trouble and hoping you can help.

    In the “author bio” section, which uses author.bio.php, there is a place that displays url & social media account links if an author has filled them in. If an Author has *not* filled them in, it still displays the ‘connect with (author name) ->” (using printf) but doesn’t show any icons/links.

    I want to display a *different* message if there are NO url & social links entered, and have tried a few things such as testing (if) those user metadata fields are empty or not, can I can get close, but no banana.

    I know it seems like it should be easy but I can’t come up with a query that returns true if all those variables are empty (I’ve tried using the PHP ’empty’ and ‘!isset’).

    This method uses empty:

    if ( ( empty(the_author_meta('url') ) ) && ( empty(the_author_meta('twitter') ) ) && ( empty(the_author_meta('facebook') ) ) && ( empty(the_author_meta('googleplus') ) ) && ( empty(the_author_meta('linkedin') ) ) ) {
    				printf( wp_kses( __( 'Apparently %u isn\'t interested in connecting. Harrumph.', 'quark' ), array(
    					'span' => array(
    						'class' => array() )
    				) ), get_the_author_meta( 'first_name') );
    			}

    But it just echos the data from those fields when they ARE filled in (basically on ALL authors) and still prints the message that it’s suppose to print only if they are NOT filled in.

    This method uses !isset:

    if ( ( !isset(the_author_meta('url') ) ) && ( !isset(the_author_meta('twitter') ) ) && ( !isset(the_author_meta('facebook') ) ) && ( !isset(the_author_meta('googleplus') ) ) && ( !isset(the_author_meta('linkedin') ) ) ) {
    				printf( wp_kses( __( 'Apparently %u isn\'t interested in connecting. Harrumph.', 'quark' ), array(
    					'span' => array(
    						'class' => array() )
    				) ), get_the_author_meta( 'first_name') );
    			}

    But I get a fatal error

    Fatal error: Cannot use isset() on the result of a function call (you can use “null !== func()” instead) in /homepages/8/d116188896/htdocs/BAI_2016/wp-content/themes/quark/author-bio.php on line 52

    I don’t understand how to use “null !==func() so this one lost me.

    Any help would be most appreciated.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Theme Author Anthony Hortin

    (@ahortin)

    Hi Trisha,

    I presume you’re talking about the Bio that appears at the bottom of the blog posts.

    If none of the social media or website links have been entered, then nothing will be displayed. In the default Quark theme it doesn’t display any “Connect with” text.

    Here’s an image from my own test site that shows how the bio displays when none of the social media links have been entered.

    Bio

    Thread Starter TrishaM

    (@trisham)

    Hi Anthony – many thanks for the response (and also for what I consider to be a brilliant – if not the best – Theme available, free or not!).

    Yes, that’s the area I’m referring to. I’m sure if I update my version that Connect With would likely go away….BUT I really WOULD like to display a different message there IF there are no social links or website added by the author.

    Can you tell me how I can do that? I’m not a coder but I’m good at following instructions and modifying others’ code to suit my needs, and I’m learning more every day!

    Thread Starter TrishaM

    (@trisham)

    OK so I downloaded the current version and compared author-bio.php to the template I have, as well as the original version I started with.

    I think I must have found a snippet somewhere online to add the “Connect With ->” because it’s not in the original nor the current version. I’ve been using my current version for a long time, and honestly don’t recall how I came to add it, but here is the snippet I’m using:

    <p class="social-meta">
    <?php printf( wp_kses( __( 'Connect with %s <span class="meta-nav">→</span>', 'quark' ), array(
       'span' => array(
       'class' => array() )
       ) ), get_the_author_meta( 'first_name') ); ?>

    This comes just before the “if ( get_the_author_meta( ‘url’ ) ) {“

    It’s worked great but I recently discovered a few of our authors who don’t list a website or any social connections, which is why – in their case – I want to change the “Connect With ->” to something different, and that’s where I’m stuck.

    Any help would be greatly appreciated!

    Theme Author Anthony Hortin

    (@ahortin)

    Something like this should work for you.

    It’ll get all the values and if one of them isn’t empty, it’ll display the links. If they’re all empty, it shouldn’t display anything.

    $websiteurl = get_the_author_meta( 'url' );
    $twittterurl = get_the_author_meta( 'twitter' );
    $facebookurl = get_the_author_meta( 'facebook' );
    $googleurl = get_the_author_meta( 'googleplus' );
    
    <?php if ( !empty( $websiteurl ) || !empty( $twittterurl ) || !empty( $facebookurl ) || !empty( $googleurl ) ) { ?>
    	<p class="social-meta">
    		<?php printf( wp_kses( __( 'Connect with %s <span class="meta-nav">→</span>', 'quark' ), array(
    	   	'span' => array(
    	   	'class' => array() )
    	   	) ), get_the_author_meta( 'first_name') ); ?>
    		<?php if ( !empty( $websiteurl ) ) { ?>
    			<a href="<?php echo $websiteurl; ?>" title="Website"><i class="fa fa-link fa-fw"></i></a>
    		<?php } ?>
    		<?php if ( !empty( $twittterurl ) ) { ?>
    			<a href="<?php echo $twittterurl; ?>" title="Twitter"><i class="fa fa-twitter fa-fw"></i></a>
    		<?php } ?>
    		<?php if ( !empty( $facebookurl ) ) { ?>
    			<a href="<?php echo $facebookurl; ?>" title="Facebook"><i class="fa fa-facebook fa-fw"></i></a>
    		<?php } ?>
    		<?php if ( !empty( $googleurl ) ) { ?>
    			<a href="<?php echo $googleurl; ?>" title="Google+"><i class="fa fa-google-plus fa-fw"></i></a>
    		<?php } ?>
    	</p>
    <?php } ?>

    I haven’t tested this code, but barring spelling mistakes, it should work hopefully

    Thread Starter TrishaM

    (@trisham)

    Thanks Anthony! That actually works perfectly – we abandoned the idea to have an alternate message display, and your code above solved my problem of having the Connect with-> display even when no social links are entered.

    I really appreciate your help!

    Theme Author Anthony Hortin

    (@ahortin)

    No probs. Glad it helped ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Modify Author Bio when no social links entered’ is closed to new replies.