• Resolved adastra

    (@adastra)


    Here’s what I want to display:

    This article was written by Username1 with help from Username2, Username3 and Username4.

    I tried to configure the snippet provided to do this, but I always get this result:

    This article was written by Username1 with help from , Username2, Username 3 and Username4.

    As you can see, there’s a stray comma in there which I can’t get rid of. My PHP skills aren’t the best…

    Here’s my somewhat messy code:

    This article was written by
    <?php
    $i = new CoAuthorsIterator();
    $i->iterate();
    print "<strong>";
    the_author_posts_link();
    print "</strong>";
    if ($i->count() > 1) {
     echo " with help from ";
    }
    while($i->iterate()){
    		print $i->is_last() ? ' and ' : ', ';
    		print $i->is_first() ? '' : '';
    		print "<strong>";
    		the_author_posts_link();
    		print "</strong>";
    }
    ?>
    .

    https://www.ads-software.com/extend/plugins/co-authors-plus/

Viewing 1 replies (of 1 total)
  • Thread Starter adastra

    (@adastra)

    I found this solution somewhere else:

    <?php
    echo 'This article was written by';
    the_author_posts_link();
    
    $authors = new CoAuthorsIterator();
    $authors->iterate();
    if ($authors->count() > 1) {
    	echo ' with help from ';
    
    	$i = 0;
    	while($authors->iterate()) {
    		if ($i > 0) echo ', ';
    		if ($authors->is_last()) echo 'and ';
    
    		the_author_posts_link();
    		$i++;
    	}
    }
    
    echo '.';
    ?>

Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: Co-Authors Plus] Using is_first and is_last at the same time?!’ is closed to new replies.