Skip to content

Instantly share code, notes, and snippets.

@jennschiffer
Last active December 15, 2015 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jennschiffer/5315205 to your computer and use it in GitHub Desktop.
Save jennschiffer/5315205 to your computer and use it in GitHub Desktop.
printing 5 latest comments of baristanet & baristakids sites in time-descending order
<?php
// bnet comments
$commentsBNET = get_comments('number=5&status=approve');
// bkids comments
switch_to_blog( '3' );
$commentsBKIDS = get_comments('number=5&status=approve');
restore_current_blog();
// merge comments
$comments = array_merge($commentsBNET, $commentsBKIDS);
// sort comments
foreach ($comments as $comm) {
$sortKeys[] = $comm->comment_date;
}
array_multisort($sortKeys,SORT_DESC,$comments);
// splice comments array to set number
array_splice($comments, 5);
// print comments
foreach($comments as $comm) :
$class = "comment-bnet";
if ( !get_the_title($comm->comment_post_ID) ) {
switch_to_blog( '3' );
$class = "comment-bkids";
}
$url = '<a href="'. get_permalink($comm->comment_post_ID).'#comment-'.$comm->comment_ID .'" title="'.$comm->comment_author .' on '.get_the_title($comm->comment_post_ID).'">' . $comm->comment_author . ' on '.get_the_title($comm->comment_post_ID) . '</a>';
echo '<li class="' . $class . '">' . $url . '</li>';
restore_current_blog();
endforeach;
?>
@jennschiffer
Copy link
Author

THERE HAS GOT TO BE A BETTER WAY TO DO THIS

@jennschiffer
Copy link
Author

ALL CAPS LOCK COMMENTING ON GISTS

@jennschiffer
Copy link
Author

This works like shit because sometimes two of the blogs have a post with the same ID and show it will not detect the lack of title in a post outside of the current blog blargh blaasodjfosaijrowejrsdfjdsfjggggg.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment