could you teach me how can i make the read more link to open in a new window. thanks

Comments

todd nienkerk’s picture

Assigned: Unassigned » todd nienkerk
Status: Active » Fixed

You can override the theme function that generates the link: theme_ed_readmore_link().

Before:

/**
 * Theme function that wraps the rendered link.
 */
function theme_ed_readmore_link($node, $link_text, $link_options, $separator, $display) {
  // Use a <div> (block-level) element for links appended after the teaser
  if ($display == 'after') {
    $element = 'div';
    $separator = '';
  }
  else {
    // Use a <span> (inline) element for links that appear inside the teaser
    $element = 'span';
    if (empty($separator)) {
      $separator = ' ';
    }
  }

  return $separator . '<' . $element . ' class="read-more">' . l($link_text, 'node/'. $node->nid, $link_options) . '</' . $element . '>';
}

Copy this function to your theme's template.php file. Change the name so that "theme_" is replaced with your theme name (e.g., "mythemename_").

Here's the code after the change:

/**
 * Theme function that wraps the rendered link.
 */
function mythemename_ed_readmore_link($node, $link_text, $link_options, $separator, $display) {
  // Use a <div> (block-level) element for links appended after the teaser
  if ($display == 'after') {
    $element = 'div';
    $separator = '';
  }
  else {
    // Use a <span> (inline) element for links that appear inside the teaser
    $element = 'span';
    if (empty($separator)) {
      $separator = ' ';
    }
  }

  $link_options['attributes']['target'] = '_blank';

  return $separator . '<' . $element . ' class="read-more">' . l($link_text, 'node/'. $node->nid, $link_options) . '</' . $element . '>';
}

Notice I only added one line:

  $link_options['attributes']['target'] = '_blank';
dhon’s picture

it doesn't work. instead i modify the .module file of ed_readmore

i try adding a code in the function. here it is:

$link_options = array(
    'attributes' => array(
    'title' => $link_title,
    'target' => '_blank',   <---- this is the code i added
    ),
    'html' => TRUE,
  );

i know i shall not edit the module file, but it somehow works with me and that's more important i think. ^^ hope it can help to those who need it

todd nienkerk’s picture

dhon: When you say my suggestion in #1 above doesn't work, can you verify that you did the following:

(1) Edited your theme's template.php file by pasting in the code above.

(2) Changed "mythemename_" to the name of your theme followed by an underscore: "garland_ed_readmore_link", "zen_ed_readmore_link", "great_theme_ed_readmore_link", etc.

(3) Flush the theme registry. If you don't do this, Drupal won't know you added a theme override.

I tried the steps in #1 on a test site, and it worked perfectly. Please make sure you followed the three steps above.

And you're right about editing the module file: Don't do it! :)

todd nienkerk’s picture

I added a checkbox in the module settings UI that adds target="_blank" to the Read More link. This will appear in a later release.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.