I've installed the cvs version of cck. It's working fairly well. How do I add "previous page", "next page" links? I have my posts in as book pages right now and will have to convert them over. How do I add "add a child page" and "add a sibling page" links? I searched on google and drupal.org. I did not even find anyone who asked this question.

Comments

kae’s picture

I've read 37767, 45050. below is how I tried to adapt it for cck

kae’s picture

following instructions from node 45050
i put these 2 files in my fancy theme directory.
i put content in front of "test" since cck contents types seem to be actually of the syntax content-xxxx.

i made a new cck content type called test. it's on www.drupalecommerce.com

i put this in a file called content-test.tpl.php

   $next = next_prev($node->nid, 'content-test', 'next', 'Next', 'test');
   $previous = next_prev($node->nid, 'content-test', 'prev', 'Previous', 'test');
   echo "<div class=\"center\">".$previous . " | " . $next ."</div>";
 

i put this in a file called template.php

 function next_prev($current_nid, $type, $btn_type, $label, $class) {
  $query = db_query("SELECT tid FROM {term_node} WHERE nid = $current_nid;");
  $tid = db_result($query); 
  $sql = "SELECT n.nid, n.title FROM {node} n INNER JOIN {term_node} t ON n.nid = t.nid ";
  $sql .= "INNER JOIN {term_data} r ON t.tid = r.tid WHERE n.type = '".$type."' AND n.nid ";
  switch ($btn_type) {
        case "next":
                $sql .= "< ";
                break;
        case "prev":
                $sql .= "> ";
                break;
        default:
                return NULL;
                break;
  }
  $sql .= $current_nid ." AND r.tid = ". $tid ." AND n.status = 1 ORDER BY nid DESC;";
  $query = db_query($sql);
  $result = db_fetch_array($query);
  if (!$result) {
        $query = db_query("SELECT name FROM {term_data} WHERE tid = $tid;");
        $name = db_result($query);
    return l("Back To $name", "$type/tid/$tid", array("title" => $name, "class" => $class));
  } else {
    return l($label, "node/".$result['nid'], array("title" => $label, "class" => $class));
  }
}
kae’s picture

this is the error that results. what does this mean?
user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND n.status = 1 ORDER BY nid DESC' at line 1 query: SELECT n.nid, n.title FROM node n INNER JOIN term_node t ON n.nid = t.nid INNER JOIN term_data r ON t.tid = r.tid WHERE n.type = 'content-test' AND n.nid < 103 AND r.tid = AND n.status = 1 ORDER BY nid DESC; in /home/myfof/public_html/drupalecommerce/includes/database.mysql.inc on line 120.
user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 query: SELECT name FROM term_data WHERE tid = ; in /home/public_html/includes/database.mysql.inc on line 120.
user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND n.status = 1 ORDER BY nid DESC' at line 1 query: SELECT n.nid, n.title FROM node n INNER JOIN term_node t ON n.nid = t.nid INNER JOIN term_data r ON t.tid = r.tid WHERE n.type = 'content-test' AND n.nid > 103 AND r.tid = AND n.status = 1 ORDER BY nid DESC; in /home/public_html/includes/database.mysql.inc on line 120.
user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 query: SELECT name FROM term_data WHERE tid = ; in /home/public_html/includes/database.mysql.inc on line 120.

kae’s picture

possible clue. an issue related to views module and upgrading. see 51619. that person had a very similar error unrelated to cck or category.

(discovered the post by googling on "term_node" in 2nd line of funciton next_prev in the template.php I made)

disabled views. still the same error.

kae’s picture

i'm going through the code for the function next_prev. my best guess right now is that the empty tid is causing the program to crash. I checked, the test post, nid=112 has no tid and no row in table term_node.

2nd line from the code posted above
$query = db_query("SELECT tid FROM {term_node} WHERE nid = $current_nid;");
$tid = db_result($query);

any ideas on how to remedy this (and if this is indeed the problem) would be appreciated.

kae’s picture

56414 has a snippet for returning list of nodes. plan to check if it might help
54920 similar error. something about curly braces

kae’s picture

okay. i just established tid cannot be null. i put data in tid and the mysql data goes away. next--is there a better fix.

eodonnell’s picture

Hi Kae - just a message that I am looking for the same functionality, and found your post. Thank you for documenting your progress so far. I'm about to try and replicate what you're up to...