WordPress.org

Ready to get started?Download WordPress

Forums

Co-Authors Plus
Displaying custom guest author fields - better way? (1 post)

  1. rustyscratchy
    Member
    Posted 6 months ago #

    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/

Reply

You must log in to post.

About this Plugin

About this Topic

  • RSS feed for this topic
  • Started 6 months ago by rustyscratchy
  • This topic is not resolved
  • WordPress version: 3.8.1