Viewing 13 replies - 1 through 13 (of 13 total)
  • Hi JT,

    You can do it like this:

    <?php coauthors_posts_links(', ',', and '); ?>

    See the documentation here: Incorporate Co-Authors Plus Template Tags into Your Theme

    Jeremy

    Thread Starter JT

    (@jtripp81)

    Thanks so much for your response it worked perfectly!

    I have one other question. I am trying to take three feeds and run them through Yahoo pipes to display on a site in HTML format. With the code you gave me it seems that it rips out that last comma (name, and name). Below are links to show you what I am experiencing.

    You’ll see in the xml of each of these.

    https://bit.ly/11lib8G
    (doesn’t show authors in HTML viewed in Firefox and Chrome)
    (shows authors in HTML viewed in IE)

    Yahoo Pipes
    https://bit.ly/1wsyCb9

    Thanks for all your help!

    Thread Starter JT

    (@jtripp81)

    Also, is there a way to not have the comma populate if it’s just two authors, but still show properly if it’s three or more authors?

    Keep current three authors comma: joe, mike, and sam

    Current two authors: joe, and mike

    Desired two authors: joe and mike

    Thanks!

    Thread Starter JT

    (@jtripp81)

    I’ve tried every which way to remove that darn comma with two authors, but no luck what so ever.

    Current code in single.php

    by <?php if ( function_exists( ‘coauthors_posts_links’ ) ) {
    coauthors_posts_links(‘, ‘,’, and ‘);
    } else {
    the_author_posts_link();
    } ?>

    I also tried changing this code, but no luck either.

    $default_between_last = ( defined( ‘COAUTHORS_DEFAULT_BETWEEN_LAST’ ) ) ? COAUTHORS_DEFAULT_BETWEEN_LAST : __(‘, and ‘, ‘co-authors-plus’ );

    Interestingly enough found this in the changelog. It seems there was a fix for this back in 2011.

    2.5.3 (Aug. 14, 2011)
    Bug fix: Removed extra comma when only two authors were listed. If you used the COAUTHORS_DEFAULT_BETWEEN_LAST constant, double-check what you have

    I’m not sure about your first question. I inspected the pipes feed and the Oxford comma is present. Did you already fix that issue?
    https://www.dropbox.com/s/abqa33i4kh6d4v8/Screenshot%202014-11-15%2010.08.34.png?dl=0

    Anyway, I believe the relevant code for RSS is on line 30 of class-coauthors-template-filters.php in the function filter_the_author_rss

    $coauthors = (array)get_coauthors();

    I don’t see a way to hook into this, so I guess you could try modifying that line in the code directly.

    If that doesn’t work, perhaps you could post a new thread with that question.

    As for the comma being displayed for only two items, this is because it is attached with the “and” in the code we specified.

    To get around this, I must again resort to modifying the source.

    Open up template-tags.php and find this piece of code at line 164:

    // Append separators
    		if ( ! $i->is_first() && $i->count() > 2 )
    			$output .= $separators['between'];
    
    		if ( $i->is_last() && $i->count() > 1 ) {
    			$output = rtrim( $output, $separators['between'] );
    			$output .= $separators['betweenLast'];
    		}

    After that code, try add the following lines:

    // Oxford comma fix
    		if ( $i->is_last() && $i->count() > 2 ) {
    			$output = rtrim( $output, $separators['between'] );
    			$output .= $separators['between'] . $separators['betweenLast'];
    		}

    And then in the place you inserted the author list in your code, get rid of the extra comma before the “and”.

    <?php coauthors_posts_links(', ','and '); ?>

    In fact, you could probably just use the vanilla function:

    <?php coauthors_posts_links(); ?>

    Perhaps the authors could add this as an option somewhere for people who prefer the Oxford comma :-)\

    https://www.dropbox.com/s/msst4sqi4zevx2i/Screenshot%202014-11-15%2010.30.50.png?dl=0

    Thread Starter JT

    (@jtripp81)

    Thanks for doing all that for me! I ended up getting odd results with the new code.

    Using the vanilla code gives me the follwing:
    <?php coauthors_posts_links(); ?>

    name, and name | November 12th, 2014 | 08:41 pm
    name, name, and, , and name | November 7th, 2014 | 09:48 pm

    Using the code with the comma removed gives me the following:
    <?php coauthors_posts_links(‘, ‘,’and ‘); ?>

    name and name
    name, nameand, and name

    As for the Yahoo Pipes I’ll open a new thread.

    Sorry about that; I didn’t test it ??

    This works:

    // Append separators
    		if ( ! $i->is_first() && $i->count() > 2 )
    			$output .= $separators['between'];
    
    		// Oxford comma fix
    		if ( $i->is_last() && $i->count() > 2 ) {
    			$output = rtrim( $output, $separators['between'] );
    			$output .= $separators['between'] . $separators['betweenLast'];
    		}
    
    		elseif ( $i->is_last() && $i->count() > 1 ) {
    			$output = rtrim( $output, $separators['between'] );
    			$output .= $separators['betweenLast'];
    		}

    And use it with the vanilla code.

    Thread Starter JT

    (@jtripp81)

    Perfect! Thanks again! There was an extra “,” still showing so I went in and removed the comma from the code below and it worked. Is that best way to do it?

    name, name, , and name

    $default_between_last = ( defined( ‘COAUTHORS_DEFAULT_BETWEEN_LAST’ ) ) ? COAUTHORS_DEFAULT_BETWEEN_LAST : __(‘ and ‘, ‘co-authors-plus’ );

    After removing that comma it worked perfectly.

    I’m not getting an extra comma with that last code I posted:
    https://abuyasmeen.com/jquery-drag-drop-resize-to-fit-target/

    Are you inserting it with: <?php coauthors_posts_links(); ?> ?

    Ah, I see. I think you inserted that comma in a previous edit. The unmodified line reads:

    $default_between_last = ( defined( 'COAUTHORS_DEFAULT_BETWEEN_LAST' ) ) ? COAUTHORS_DEFAULT_BETWEEN_LAST :  __( ' and ', 'co-authors-plus' );
    Thread Starter JT

    (@jtripp81)

    Shoot! Thank you for catching that!

    Any luck with the RSS?

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Commas’ is closed to new replies.