You’ll probably want to replace the block entirely with something like:
<?php coauthors_posts_links(); ?>
This will give you bylines with the authors’ names linked to their archive pages.
Thread Starter
mpanty
(@mpanty)
Hi Daniel,
I tried what you suggested, though I had to expand the selection of code I replaced (the snippet I posted above was actually incomplete; replacing just that part gave me a syntax error)
I thus replaced the following:
<?php /* Post author, not shown if this is a Page post or if admin decides to hide it */ ?>
<?php if ( $post_type->name != 'page' && $graphene_settings['hide_post_author'] != true ) : ?>
<p class="post-author author vcard">
<?php
/* translators: this is for the author byline, such as 'by John Doe' */
$author_url = '<a href="' . get_author_posts_url( get_the_author_meta( 'ID' ) ) . '" class="url">' . get_the_author_meta( 'display_name' ) . '</a>';
printf( __( 'by %s', 'graphene' ), '<span class="fn nickname">' . $author_url . '</span>' );
?>
</p>
<?php endif; ?>
with what you suggested,
<?php coauthors_posts_links(); ?>
This the result:
(first JK1 image is with original loop file, JK2 image is modified)
http://juventiknows.com/wp-content/uploads/2012/03/JK1.jpg
http://juventiknows.com/wp-content/uploads/2012/03/JK2.jpg
As you can see, I’ve lost the proper formatting as well as the “by” word.
I’d be extremely grateful if you could help me further with this Daniel, though I predict that you taking a look at the FULL loop.php file might be necessary. I’ve posted the original here on pastebin:
http://pastebin.com/Gfjfja1J
Try:
<?php if ( $post_type->name != 'page' && $graphene_settings['hide_post_author'] != true ) : ?>
<p class="post-author author vcard">
<span class="fn nickname">
<?php echo coauthors_posts_links(); ?>
</span>
</p>
<?php endif; ?>
This will retain some of the original CSS
Thread Starter
mpanty
(@mpanty)
I finally got around to trying your last suggestion Daniel.
As far as CSS goes, it worked: the author name appears where it should be.
However, I created two additional problems:
1) I lost the “by” word (“by” John Doe…)
2) The author name(s) appear in duplicate
http://juventiknows.com/wp-content/uploads/2012/03/JK3a.jpg
1) I lost the “by” word (“by” John Doe…)
Add “By ” in front of <?php echo coauthors_posts_links(); ?> and it will reappear
2) The author name(s) appear in duplicate
The co-authors code must be executing twice. Are you sure you don’t have coauthors_posts_links() in there twice?
Thread Starter
mpanty
(@mpanty)
I think I fixed it.
1) Your “by” fix worked.
2) I removed echo in the snippet of code you suggested. Now it’s working fine.
<?php if ( $post_type->name != 'page' && $graphene_settings['hide_post_author'] != true ) : ?>
<p class="post-author author vcard">
<span class="fn nickname">
by <?php coauthors_posts_links(); ?>
</span>
</p>
<?php endif; ?>
Just one thing: predictably, if I de-activate Co-Authors, my site gives me a fatal error due to those lines of code in loop.php. I wonder if there is a way to set up the code so that if Co-Authors isn’t active, the original code is used instead.
Kinda what’s suggested in the ‘other notes’ section of the plug-in’s website:
if(function_exists('coauthors_posts_links'))
coauthors_posts_links();
else
the_author_posts_link();
…except in a way that the else conditions somehow include the original lines of code I posted above.
I know I might this might be a little bit more complicated, so if it is I’m quite happy with just having the plug-in functioning properly. But it’d be nice to have a ‘clean’ solution to the whole problem. 🙂
Thank you very much for all your help by the way Daniel! 🙂 Much appreciated.
Thread Starter
mpanty
(@mpanty)
Oh, an added note for users who might have the same problem: the above fix works only for your homepage (which uses loop.php).
For single posts, you need to modify loop-single.php pretty much the same way.
You could probably use that “if…else” function in a PHP widget in a Graphene action hook widget area, and then just suppress the regular author area with a bit of custom CSS.
Glad to hear you figured it out 🙂
With regards to your conditional inclusion of the code, you can use the “if… else” statement with a larger block of code. Basically:
if ( function_exists( 'coauthors_posts_links' ) ) {
// Do the new co-authors block of code
} else {
// Do your original block of code
}
Thread Starter
mpanty
(@mpanty)
kjodle sorry, I have no idea what you just said. 🙂
Daniel, your solution doesn’t seem to work properly because the “if… else” code doesn’t execute. Either that or I didn’t enter it correctly.
http://juventiknows.com/wp-content/uploads/2012/03/JK3b.jpg
Notice how both the original code and the co-authors code execute simultaneously, but the “if… else” function is ignored completely (the lines of code appear on the webpage!)
Here’s how I input it in loop.php:
if ( function_exists( 'coauthors_posts_links' ) ) {
<?php if ( $post_type->name != 'page' && $graphene_settings['hide_post_author'] != true ) : ?>
<p class="post-author author vcard">
<span class="fn nickname">
by <?php coauthors_posts_links(); ?>
</span>
</p>
<?php endif; ?>
} else {
<?php /* Post author, not shown if this is a Page post or if admin decides to hide it */ ?>
<?php if ( $post_type->name != 'page' && $graphene_settings['hide_post_author'] != true ) : ?>
<p class="post-author author vcard">
<?php
/* translators: this is for the author byline, such as 'by John Doe' */
$author_url = '<a href="' . get_author_posts_url( get_the_author_meta( 'ID' ) ) . '" class="url">' . get_the_author_meta( 'display_name' ) . '</a>';
printf( __( 'by %s', 'graphene' ), '<span class="fn nickname">' . $author_url . '</span>' );
?>
</p>
<?php endif; ?>
}
You need to wrap it in some PHP tags… 🙂
if ( function_exists( 'coauthors_posts_links' ) ) {
becomes
<?php if ( function_exists( 'coauthors_posts_links' ) ) { ?>
Thread Starter
mpanty
(@mpanty)
Tried that Daniel, but I get a parse error.
I tried two things: wrapping just the first line in PHP tags (like in your example), or the whole block of code (i.e. putting ?> right after the } at the end). I still get a parse error. Do I need more PHP tags in between?
It would probably be easier if you could show me where you’d put all the tags into the whole block of code I posted above.
Yep, it should look something like this: https://gist.github.com/2210295
Thread Starter
mpanty
(@mpanty)
Worked!! Problem solved! 😀
Plug-in is now working fine, and if I de-activate it, the site displays a single author, as it should by default graphene settings!
Once again, thank you very much for all your help! 🙂