Hello,

I notice the comment title for Pingbacks show as "Pingback". I have a recent comments block and I have a lot of links with the same title. Could the first few words of the comment be used as titles instead?

cheers,
G

Comments

giorgio79’s picture

For this I believe at line 300 we would need to change

  $edit = array(
    'nid' => $nid,
    'subject' => t('Pingback'),
    'comment' => '[...] '. $excerpt .' [...]',
    'hostname' => ip_address(),
    'format' => variable_get('pingback_input_format', FILTER_FORMAT_DEFAULT),
    'name' => $title,
    'homepage' => $pagelinkedfrom,
  );

to this

  $edit = array(
    'nid' => $nid,
    'subject' => $title." ".t('Pingback'),
    'comment' => '[...] '. $excerpt .' [...]',
    'hostname' => ip_address(),
    'format' => variable_get('pingback_input_format', FILTER_FORMAT_DEFAULT),
    'name' => $title,
    'homepage' => $pagelinkedfrom,
  );

I am just adding this $title." ". to the subject which is saved as the title in comment table.

andreashaugstrup’s picture

Status: Active » Closed (won't fix)

Since the comment object can't have a custom status the only way to distinguish pingbacks from regular comments is by filtering on the title of the comment. That's why the title is left as "Pingback".

If you want a different title I suggest you change this in the theming layer.

giorgio79’s picture

Status: Closed (won't fix) » Postponed (maintainer needs more info)

Hi Andreas,

Thanks for coming back.

In fact you can distinguish pingbacks because they have their own input filter as per Greg's video tutorial.

Looking in the comments table, the input filter is a definite distinguisher.

Cheers,
G

kvarnelis’s picture

Why can't there be an option for this? I'd love to have my Pingbacks say the title of the pinging post, or Pingback from: someblog.wordpress.com or something more than Pingback, which is going to be a mystery, I think, to the majority of my users.

jonathan1055’s picture

I wanted to do the same thing, and achieved it by making use of mytheme_preprocess_comment(). It could also be done using phptemplate_preprocess_comment(). Whichever you use, it should go in your themes template.php file. Here is an example which sets the title of the comment to 'Pingback from' followed by the name of the page it came from, which is also a link to that site. I think this is what you wanted:

/**
 * Override or insert variables into the comment templates.
 *
 * @param $vars
 *   An array of variables to pass to the theme template.
 * @param $hook
 *   The name of the template being rendered ("comment" in this case.)
 */
function mytheme_preprocess_comment(&$vars, $hook) {
  $this_comment = $vars['comment'];
  $is_pingback=($this_comment->subject=='Pingback');
  if ($is_pingback) {
    $vars['title']='Pingback from '.l($this_comment->name,$this_comment->homepage);
  }
}

I developed a slightly more complex version, which caters for all types of comments and says whether it is a comment, a reply or a pingback. Note that in my theme I have removed the title of the comment, and use two variables 'submitted' and 'submitted when', but the principle is the same.

/**
 * Override or insert variables into the comment templates.
 *
 * @param $vars
 *   An array of variables to pass to the theme template.
 * @param $hook
 *   The name of the template being rendered ("comment" in this case.)
 */
function mytheme_preprocess_comment(&$vars, $hook) {
  $this_comment = $vars['comment'];
  $is_pingback=($this_comment->subject=='Pingback');
  $is_reply=($this_comment->depth > 0 or $this_comment->pid);
  $vars['submitted'] = t('!what !username',
                              array('!what'   => ($is_pingback ? 'Pingback from' : ($is_reply ? 'Reply from' : 'Comment by')),
                                    '!username' => theme('username', $this_comment)
                                 ));
  $vars['submitted_when'] = t('Submitted on @datetime', array('@datetime' => format_date($this_comment->timestamp,'large')));
}

[apologies for the indentation, can't seem to get it right because my text input box is not fixed-width font]

Hope that helps you to get going on this.

Jonathan

andreashaugstrup’s picture

Status: Postponed (maintainer needs more info) » Active

Good point about using the format to distinguish. If someone makes a patch that makes an option out of the pingback title I will commit it. Should probably be able to choose between using "pingback", the first few characters of the pingback or a custom text as the comment title.