0

As said in the title, I'm having a problem with the "read more" link. I made my own view (wie-zijn-we-pagina) and content type (wie-zijn-we-) and am trying to add a custom "read more" and "add new comment" link to it. The code that I'm using gives me the correct custom "Add new comment" link but the "Read more" link doesn't work. At first it didnt even show up.

My code:

function ap_hogeschool_theme_preprocess_node(&$variables){
$variables['content']['links']['comment']['#links']['comment-comments'] = FALSE; 
if($variables['view'] && $variables['type'] == 'wie_zijn_we_')
    {   
    $variables['content']['links']['node']['#links']['node-readmore']['title'] ='<div class="custom-add-read-more"> </div>';
    $variables['content']['links']['comment']['#links']['node-readmore']['html'] = TRUE;
    $variables['content']['links']['comment']['#links']['comment-add']['title'] = '<div class="custom-add-comment"> </div>';
    $variables['content']['links']['comment']['#links']['comment-add']['html'] = TRUE;

} 
}

I don't know if the part where i call the view and content type is correct... I'm still a new drupal user.

An image of what i have:

enter image description here

An image of what in need to have:

enter image description here

Could somebady please help me along?

1 Answer 1

1

You have a mistake on your code. Instead of $variables['content']['links']['node'] you wrote $variables['content']['links']['comment'].

Corrected code:

function ap_hogeschool_theme_preprocess_node(&$variables){

  $variables['content']['links']['comment']['#links']['comment-comments'] = FALSE;

  if( $variables['type'] == 'wie_zijn_we_' && $variables['view_mode'] == 'teaser' ){

     $variables['content']['links']['node']['#links']['node-readmore']['title'] ='<div class="custom-add-read-more"> </div>';
     // Mistake was in this line:
     $variables['content']['links']['node']['#links']['node-readmore']['html'] = TRUE;
     $variables['content']['links']['comment']['#links']['comment-add']['title'] = '<div class="custom-add-comment"> </div>';
     $variables['content']['links']['comment']['#links']['comment-add']['html'] = TRUE;

   } 
  }
19
  • Hey Rufein, thx alot, This work perfectly. Again a dum mistake from my part :(. Commented May 7, 2013 at 11:29
  • 1
    Don't worry, everybody learns making mistakes. We are here to learn. Good luck on your project.
    – Rufein
    Commented May 7, 2013 at 11:33
  • Eu Rufein, I just noticed. I can see my custom link now but it can't be clicked, its like the link part is missing and it just shows a nice picture now... Am I still doing something wrong? Commented May 7, 2013 at 11:49
  • I think it's OK. You could check with firebug if an <a> wrapper is printed in code. This tag should wrap the title you have writted in your preproccess hook. If it's printed, then with CSS you will solve the problem.
    – Rufein
    Commented May 7, 2013 at 12:02
  • I just checked and it doesn't work at all. There is one post where the "add new comment" works but on all the other posts it does not place a <a> wrapper around the links... Is it possible that my new class go's in conflict with the one from my front page? (if I use the first part of the following code: if($variables['view'] && $variables['type'] == 'wie_zijn_we_') then i get tons of errors on my view saying that it doesn't accept view as a variable or something.) Commented May 7, 2013 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.