I want to put "read more" after the teaser and not together other links. So I lurked this site and after some tries I get the following code (i use php template on drupal 4.6):

<div class="node<?php print ($sticky) ? " sticky" : ""; ?>">
  <?php if ($page == 0): ?>
    <h2><a href="/<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h2>
  <?php endif; ?>
  <?php print $picture ?>
  <div class="info"><?php print $submitted ?> <?php print $terms ?></div>
  <div class="content">
  <?php
    if($main && $node->readmore) {
        $content = "$node->teaser";
        $pos = strrpos ($content, "</p>");
        $content = substr ($content,0,$pos);
        $content .= " ... " . l(t('read more'), "node/$node->nid", array('title' => t('Read the rest of this posting.'), 'class' => 'read-more')) . "</p><hr class=\"incontent\" />";
        if ($node->links) {
        $linkoli=$node->links;
            if ($key=array_keys ($linkoli,(l(t('read more'), "node/$node->nid", array('title' => t('Read the rest of this posting.'), 'class' => 'read-more'))))) unset($linkoli[$key[0]]);
            $links = theme("links", $linkoli);
        }
    print $content;
    }
    else print $content;
   ?>
   </div>

   <?php if ($links): ?>
    <?php if ($picture): ?>
      <br class='clear' />
    <?php endif; ?>
   <div class="links"> &raquo; 
       <?php print $links ?>
   </div>
  <?php endif; ?>
</div>

the only problem I found till now is that "read more" is put in ALL event nodes even if there is nothing else to show (you can look here, the site is in italian "read more" is "leggi tutto").
Cheers, Aress

Comments

Bèr Kessels’s picture

t is uncleqr to me why you do

        $pos = strrpos ($content, "</p>");
         $content = substr ($content,0,$pos);

This will break more complex HTML like tables, or Divs containing the paragraph tag. What is wrong with the default teaser?

[Bèr Kessels | Drupal services www.webschuur.com]

davec611’s picture

Ber,

If you go to the following thread, you will see a discussion about what is wrong with the teaser in its current placing.

http://drupal.org/node/21538

Also there is some more code to make the change aress requires. Unfortunately it applies to a specific theme instead of being general

Bèr Kessels’s picture

I undertstand the need of placing the Read More somewhere else. But I want to know why you chop off the teaser, at a closing P-tag.
Can you explain why you do that? It WILL break your site completely a lot of cases, wheremore complex HTML is used in the body or teaser.

---
Next time, please consider filing a support request.

[Bèr Kessels | Drupal services www.webschuur.com]

Aress’s picture

Don't look at my code as an example of good programming. My knowledge of php is limited to this site and a 40-pages' book.
The code I wrote works for my need, look here. I've got only the problem with events. Other solutions are welcomed but I don't know how to write them :(

In my past tries, I got this result:

<p>teaser</p>
<p>read more</p>

to put "read more" after teaser I decided to delete < /p> next to teaser and append the "read more" and this code:

<?php
        $pos = strrpos ($content, "</p>");
        $content = substr ($content,0,$pos);
?> 

should do the job (I think).
Aress

P.S. I didn't think this change could break the site. You are right but is a minor issue for me because only the admin (I) can write complex html.

Marc Bijl’s picture

Hi Aress,

I had the same problem with separating the "read more" link. Therefore I was very much interested in your solution, as it places the link right at the end of the teaser: excellent!

However, at my site (and I think in general), it does not work in case the teaser has more than one paragraph... The link will be added right behind the end of the first paragraph - while the others won't be visible anymore.

Do you know how to solve this? Or does anyone know if there's another way of positioning the "read more" link at the end of the whole teaser?

Cheers,
Marc
___________________
discover new oceans
lose sight of the shore