Created
April 12, 2020 13:07
-
-
Save jamesmthornton/43f3d80248c92d8c2a0c0d99b1edb226 to your computer and use it in GitHub Desktop.
Output internal pingback/trackbacks on Genesis Wordpress sites
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// remove whatever action your current ping method relies on, typically your comments template | |
remove_action( 'genesis_pings', 'genesis_do_pings' ); | |
// you can use the comments_text filter hook if you don't have genesis | |
add_filter( 'genesis_pings', function( $ifca_pings ) { | |
if ( acme_post_has( 'pings', get_the_ID() ) ) { | |
echo'<div id="internal-links" class="comment-respond entry-pings">'; | |
echo '<h3>Articles referencing this one</h3>'; | |
echo '<ol>'; | |
wp_list_comments( array( | |
'style' => 'ul', | |
'type' => 'pings', | |
'callback' => 'better_pings', | |
'short_ping' => true | |
) ); | |
echo'</ol></div>'; | |
// dont judge my quick and dirty inline css - i know its messy | |
echo '<style> | |
.content .entry { | |
padding-bottom: 0; | |
} | |
#internal-links.comment-respond.entry-pings { | |
font-size: 1.8rem; | |
padding: 0; | |
} | |
#internal-links.entry-pings ol { | |
list-style-position: inside; | |
list-style-type: lower-roman; | |
} | |
#internal-links.entry-pings ol li { | |
padding: 28px 25px 24px 36px; | |
list-style-type: lower-roman; | |
display: list-item; | |
} | |
#internal-links.entry-pings ol li:nth-of-type(odd) { | |
background-color: #f4f4f4; | |
border: 1px solid #eee; | |
} | |
#internal-links .ref-block { | |
margin-left: 30px; | |
margin-top: -30px; | |
} | |
#internal-links .ref-block a { | |
font-weight: bold; | |
} | |
.content .entry { | |
margin-bottom: 0; | |
} | |
</style>'; | |
} | |
return $ifca_pings; | |
}, 9 ); | |
// annoyingly, all trackbacks/pingbacks are treated like comments in the db | |
// linking post title gets saved as comment_author() | |
// linking post url gets saved as comment_author_url() | |
function better_pings($comment, $args, $depth ) { | |
?> | |
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>"> | |
<div class="ref-block"><?php | |
echo '<i> <a href="' . get_comment_author_url() . '">' . get_comment_author() . '</a>'; | |
// this is just to change the default [...] ellipses output to not have brackets | |
$comment_text = '…' . get_comment_text() . '… </i>'; | |
$comment_text = strval( str_replace('[…]', '', $comment_text )) ; | |
echo $comment_text; | |
?></div> | |
</li> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment