WordPress.org

Support

Support » Plugins and Hacks » Displaying custom guest author fields – better way?

Displaying custom guest author fields – better way?

  • rustyscratchy
    Member

    @rustyscratchy

    I’ve been trying to display a job description (if it exists in the user profile) and company name (if it exists) next to the author, like this:

    John Doe, Marketing Directory, XYZ Widgets Inc.

    I created these guest author profile fields in functions.php, and borrowing from this code I think I have it working. I’m wondering if there is a more efficient way to approach it. Any suggestions?

    Heading and byline in index.php:

    <h1 class="post-title"><?php the_title(); ?></h1>
    <?php mytheme_posted_on(); ?>

    In functions.php:

    // Allow multiple authors to show in layout - for Co-Authors Plus
    function mytheme_posted_on() {
    	if ( function_exists( 'coauthors_posts_links' ) ) {
    		$i = new CoAuthorsIterator();
    
    		$i->iterate();
    		// first author
    		echo "by <strong>";
    		the_author();
    		echo "</strong>";
    		if ( get_the_author_meta('jobdescription') ) :
    			echo ", ";
    			the_author_meta('jobdescription');
    		endif;
    		if ( get_the_author_meta('company') ) :
    			echo ", ";
    			the_author_meta('company');
    		endif;
    		echo " &mdash; ";
    		the_date();
    
    		// next author
    		while($i->iterate()){
    			echo "<br>and ";
    		   	echo "<strong>";
    		        the_author();
    		        echo "</strong>";
    			if ( get_the_author_meta('jobdescription') ) :
    				echo ", ";
    				the_author_meta('jobdescription');
    			endif;
    			if ( get_the_author_meta('company') ) :
    				echo ", ";
    				the_author_meta('company');
    			endif;
    		}
    	} else {
    	the_author();
    	}
    
    }

    https://wordpress.org/plugins/co-authors-plus/

  • The topic ‘Displaying custom guest author fields – better way?’ is closed to new replies.