|
#1
Jan 13, 2011, 11:02 PM
|
|
I can't figure this out, and am now wondering if it is an ATA 3.5.3 issue: In comments.php I've added in the separate trackbacks/comments section the following code: (see my related post)
Code:
if ( ! empty($comments_by_type['pings']) ) : //only placed in if there are indeed pingbacks
echo "inside";
echo "<BR><h3 id='comments'>Pingbacks:</h3>";
echo "<div id='pings'>";
wp_list_comments('type=pings&callback=list_pings');
echo "</div>";
endif;
//end add-in
This is apparently the standard way to go about this with others, but it my if statement is being completely ignored here. That is, it never gets inside, even on pages with pingbacks. (Note, the code inside the if statement works as expected if I get rid of the if statement.) So, something is wrong with the if statement, and I don't think it is the code or logic itself. Rather, I wonder if ATA 3.5.3 does not have the function
Code:
! empty($comments_by_type['pings'])
Does anyone have insights on this?
Thanks,
Derek
http://www.1775thebook.com
Last edited by derekwbeck; Jan 13, 2011 at 11:03 PM.
Reason: signature
|
#3
Jan 15, 2011, 06:22 AM
|
|
|
|
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
|
|
Where did you set $comment_by_type? Is it a local or global variable?
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
|
#4
Jan 15, 2011, 12:30 PM
|
|
code at the very tail of functions.php:
Code:
<?php
//add-in by derek beck for
//from www.wphacks.com/separating-trackbacks-from-comments-in-wordpress-2-7/
function list_pings($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
?>
<li id="comment-<?php comment_ID(); ?>"><?php comment_author_link(); ?>
<?php } ?>
<?php
add_filter('get_comments_number', 'comment_count', 0);
function comment_count( $count ) {
if ( ! is_admin() ) {
global $id;
$comments_by_type = &separate_comments(get_comments('status=approve&post_id=' . $id));
return count($comments_by_type['comment']);
} else {
return $count;
}
}
//end add-in
?>
following the instructions from http://wphacks.com/separating-trackb...wordpress-2-7/
Last edited by derekwbeck; Jan 15, 2011 at 12:59 PM.
|
#5
Jan 15, 2011, 06:07 PM
|
|
Juggledad, got your reply by email, but it somehow did not post here. In the email you wrote:
Quote:
So you have created a local variable in function.php and another in comments.php. They are independent of each other. Try making them both a global.
|
How do I set a global variable?
|
#6
Jan 16, 2011, 05:53 AM
|
|
|
|
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
|
|
Do a google search
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
|
#7
Jan 21, 2011, 02:32 AM
|
|
I added
global $comments_by_type;
just after
global $id;
in the code above, in functions.php, but nothing changes... any ideas?
|
#8
Jan 21, 2011, 05:58 AM
|
|
|
|
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
|
|
doing that will make it a global in functions.php, but what about in comments.php? without naming it a global there, it is still a local variable and different from the global even though they have the same name.
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
|
#9
Jan 21, 2011, 11:55 AM
|
|
I figured merely adding
global $comments_by_type;
to comments.php would solve it... which I added just before the if statement above that is not successfully being entered, but that did not solve it.
Am I declaring these globals right?
|
#10
Jan 21, 2011, 12:55 PM
|
|
|
|
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
|
|
looks like it, I add some echo statements in to see if the value you think should be there is really there.
HTML Code:
echo '<strong>comments_by_type='.$comments_by_type.'</strong><br>';
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
|
#11
Jan 21, 2011, 07:51 PM
|
|
hmm... I've tried such echo statements too... I get nothing for the variable. Using your code, I simply get:
comments_by_type=
so perplexing...
thank you for your steadfast assistance juggledad!
|
#12
Jan 27, 2011, 02:18 AM
|
|
Okay, I've figured it out... comments_by_type requires a strange explicit declaration, in the comments.php, as follows:
Code:
$comments_by_type = &separate_comments($comments); //strangely, this has to be declared explicitly
if ( ! empty($comments_by_type['pings']) ) { //only placed in if there are indeed pingbacks
Thus, the entire code to separate out trackbacks (be sure to select "Yes" for this in the ATA theme under comments!!) is as follows:
In the comments.php, where you find the following:
Code:
wp_list_comments(array(
'avatar_size'=>$bfa_ata['avatar_size'],
'reply_text'=>__(' · Reply','atahualpa'),
'login_text'=>__('Log in to Reply','atahualpa'),
'callback' => bfa_comments,
'type' => 'pings'
));
} else {
comment that portion out, and replace it with all of the following:
Code:
//wp_list_comments(array(
//'avatar_size'=>$bfa_ata['avatar_size'],
//'reply_text'=>__(' · Reply','atahualpa'),
//'login_text'=>__('Log in to Reply','atahualpa'),
//'callback' => bfa_comments,
//'type' => 'pings'
//));
//above commented out and this portion replaced by derek beck
$comments_by_type = &separate_comments($comments); //strangely, this has to be declared explicitly
if ( ! empty($comments_by_type['pings']) ) { //only placed in if there are indeed pingbacks
echo "<BR><h3 id='comments'>Pingbacks:</h3>";
echo "<div id='pings'>";
wp_list_comments('type=pings&callback=list_pings');
echo "</div>";
}
//end add-in
} else {
Then, in functions.php, add the following to the very bottom:
Code:
<?php
//add-in by derek beck for trackback separation
function list_pings($comment, $args, $depth) { //this function is a callback set in comments.php to check for the number of pings within the comments
$GLOBALS['comment'] = $comment;
?>
<li id="comment-<?php comment_ID(); ?>"><?php comment_author_link();
}
add_filter('get_comments_number', 'comment_count', 0);
function comment_count( $count ) { //this function updates the comment count so that it does not include in the total the number of pings
if ( ! is_admin() ) {
global $id;
$comments_by_type = &separate_comments(get_comments('status=approve&post_id=' . $id));
return count($comments_by_type['comment']);
} else {
return $count;
}
}
//end add-in
?>
That makes it work. Note with the <div id='pings'> declaration you can style the pings as you desire.
See my site below for examples in the blog entries... Hope this is useful for someone!
Derek Beck
www.derekbeck.com/1775
|
|