Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit ea483ea

Browse files
committed
Add list_linkbacks function for additional flexibility.
1 parent ed37d78 commit ea483ea

File tree

3 files changed

+58
-6
lines changed

3 files changed

+58
-6
lines changed

css/semantic-linkbacks.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99
text-align: center;
1010
}
1111

12+
.mention-list .hide-name {
13+
display: none;
14+
}
15+
1216
.mention-list li img {
1317
text-align: left;
14-
border-radius: 20px;
18+
border-radius: 50%;
1519
display: block;
1620
}

includes/functions.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,51 @@ function has_linkbacks( $type = null, $post_ID = null ) {
9292
return false;
9393
}
9494

95+
/**
96+
* Return marked up linkbacks
97+
* Based on wp_list_comments()
98+
*/
99+
function list_linkbacks( $args, $comments ) {
100+
$defaults = array(
101+
'avatar_size' => 64,
102+
'style' => 'ul', // What HTML type to wrap it in. Accepts 'ul', 'ol'.
103+
'style-class' => 'mention-list', // What class to assign to the wrapper
104+
'li-class' => 'single-mention', // What class to assign to the list elements
105+
'echo' => true // Whether to echo the output or return
106+
);
107+
108+
$r = wp_parse_args( $args, $defaults );
109+
/**
110+
* Filters the arguments used in retrieving the linkbacks list
111+
*
112+
*
113+
* @param array $r An array of arguments for displaying linkbacks
114+
*/
115+
$r = apply_filters( 'list_linkbacks_args', $r );
116+
if ( ! is_array( $comments ) ) {
117+
return;
118+
}
119+
if ( is_string( $r['li-class'] ) ) {
120+
$classes = explode( ' ', $r['li-class'] );
121+
}
122+
else {
123+
$classes = $r['li-class'];
124+
}
125+
$classes[] = 'h-cite';
126+
$classes = join( ' ', $classes );
127+
$return = sprintf( '<%1$s class="%2$s">', $r['style'], $r['style-class'] );
128+
foreach ( $comments as $comment ) {
129+
$return .= sprintf( '<li class="%1$s">
130+
<a class="u-url" href="%2$s">
131+
<span class="p-author h-card">%3$s</span>
132+
<a class="hide-name p-name u-url" href="%4$s">%5$s</a>
133+
</span></a>
134+
</li>',
135+
$classes, get_comment_link( $comment ), get_avatar( $comment, $r['avatar_size'] ), get_comment_author_url( $comment ), get_comment_author( $comment ) );
136+
}
137+
$return .= sprintf( '</%1$s>', $r['style'] );
138+
if ( $r['echo'] ) {
139+
echo $return;
140+
}
141+
return $return;
142+
}

templates/linkbacks.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
<div class="likes">
33
<h3>Likes</li>
44

5-
<ul class="mention-list">
6-
<?php foreach ( get_linkbacks( 'like' ) as $like ) : ?>
7-
<li><?php echo get_avatar( $like, 50 ); ?></li>
8-
<?php endforeach; ?>
9-
</ul>
5+
<?php
6+
list_linkbacks( array(
7+
'li-class' => array( 'single-mention', 'p-like' )
8+
),
9+
get_linkbacks( 'like' ) ); ?>
1010
</div>
1111
<?php endif; ?>
1212

0 commit comments

Comments
 (0)