Hi,
how can I add 3 links at bottom of an article that allow to go back to index of issue, go to previous article and next article?
Especially a back to index should be great...
I don't think is difficult but I don't know php, so if someone can tell me what modify and where...
Thanks.

Comments

romca’s picture

Status: Active » Closed (fixed)

Hi,
you should use the standard Drupal's themeing
see:
http://drupal.org/node/46012
and especially:

(if you want to theme journal specific pages, ie those with /ejournal - you can do so in you custom template, look at the theme_ikaros.inc for examples)

if you have node-type "articles", create "articles-node.tpl" inside of you theme folder

look at node.tpl, copy it to the new file and add this snippet to the appropriate place (not tested):

if($node->ejournal->journal->jid) {
  #this will retrieve articles for the current issue (not full text nodes, but info about them)
  $articles = array_keys(_ejournal_issue_get_articles($node->ejournal->journal, node->ejournal->journal->iid));
  $current = array_search($node->nid, $articles);
  
  if ($articles[$current-1]) {
    print l(t('previous'), 'node/'.$articles[$current-1]);
  }
  
  print l(t('this issue'), ejournal_path_set('iid' => $node->ejournal->journal->iid));
  
  if ($articles[$current+1]) {
    print l(t('next'), 'node/'.$articles[$current+1]);
  }
}
drein’s picture

Status: Closed (fixed) » Postponed (maintainer needs more info)

Hi,
I create a custom theme for ejournal, called theme_test.inc, I pasted your snippets there and I activated that layout.
I had 2 3 syntax error, anyway I think having corrected them, but I can't see any "previous, next" link when reading an article, I'm sorry.
could you read this code and tell me if there is something wrong?

if($node->ejournal->journal->jid) {
$articles = array_keys(_ejournal_issue_get_articles($node->ejournal->journal, $node->ejournal->journal->iid));
$current = array_search($node->nid, $articles);
if ($articles[$current-1]) {
print l(t("Articolo precedente"), 'node/'.$articles[$current-1]);
}

print l(t("Ritorna all'indice di questa edizione"), ejournal_path_set('iid', $node->ejournal->journal->iid));

if ($articles[$current+1]) {
print l(t('Articolo successivo'), 'node/'.$articles[$current+1]);
}
}
drein’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

ok, I'm a stupid, it's clear that this snippet must be copied into a real file, like your theme or a node.template.tpl, not be alone!
ok, I'll give a try tormorrow.

drein’s picture

Status: Closed (fixed) » Postponed (maintainer needs more info)

Hmmmmm.
There are errors in the php scripts, so I can't know how to figure out. I copied the snippets to node-mytypeofcontents.tpl.php, and effectively now there is "issue" link displayed.
but this link, that should return to index, give a page not found, its path is something like:
www.mysite.com/i/i/i/i/i

and the php line is this:
print l(t("Issue Ritorna all'indice di questa edizione"), ejournal_path_set('iid', $node->ejournal->journal->iid));

I don't know why but unfortunately, the previous and next article doesn't appear.

romca’s picture

ok,the good thing is that now we know the theme is called and the ejournal data is there

please find some of the lines and replace them with this:

$articles = array_keys(_ejournal_issue_get_articles($node->ejournal->journal, $node->ejournal->issue->iid));

and

print l(t("Ritorna all'indice di questa edizione"), ejournal_path_set(array('iid' => $node->ejournal->issue->iid)));

if it still does not work, then use this to debug, see if we got articles, if there is the issue etc

print_r($articles);
...
#or 
...
print_r($current);
drein’s picture

yeaaaah! it works at 99%!
great, now we have previous and next article working well. the only thing is that the "back to index" brings to the "ejournal" index of all the journals, not to the index of current issue.
the path is something like:
www.mysite.com/ejournal/show/_/_/4

I think it's the last thing, anyway I'm very happy just so.

romca’s picture

oh yeeah, i forgot to pass the journal-id
do this:

print l(t("Ritorna all'indice di questa edizione"), ejournal_path_set(array('jid' => $node->ejournal->journal->jid, 'iid' => $node->ejournal->issue->iid)));

the link sohould be: www.mysite.com/ejournal/show/1/_/4

drein’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

Ok!
that's right, now all is working well.
for other people that in future will read this topic, I post all the snippet:

if($node->ejournal->journal->jid) {
$articles = array_keys(_ejournal_issue_get_articles($node->ejournal->journal, $node->ejournal->issue->iid));
$current = array_search($node->nid, $articles);
if ($articles[$current-1]) {
print l(t("Previous article"), 'node/'.$articles[$current-1]);
}
if ($articles[$current+1]) {
print l(t('Next Article'), 'node/'.$articles[$current+1]);
}

print l(t("Back to index"), ejournal_path_set(array('jid' => $node->ejournal->journal->jid, 'iid'=> $node->ejournal->issue->iid)));
}

if someone has problem with "" , replace with '' .
Thanks again.

drein’s picture

Sorry, a question if you can help me:
the snippet is really ok, there is only a problem:
when you are in the archive page and select a category for seeing articles about that, I can view all the list of articles but, there are also the link "previous, next, , and back to index" for each article and I'd like to remove them from there, it is too much redoundant...
have you any ideas how to remove these links?

romca’s picture

if you theme only a certain node-type, then the links will display only for those node-types
something like node-article.tpl.php

you should not have the snippet in the general theme because then it gets applied to every page (which does not have its own themeing function)

drein’s picture

yes in fact.
The problem is just here, I have the snippet in a node-article.tpl... not in the general node or in the ejournal standard theme...
this is the strange thing!
mmm, but, when I am in the list of articles of a category, each article has 5 6 lines of text, then the button "read all".
do you think that the teaser recalls the node-article.tpl?