I am looking in to using the i18n_db_rewrite_sql function to select content by the content selection setting of the website. Maybe there is another way to maintain the preference set for content selection when the prev /next cron is run?

Comments

opi’s picture

submitting

Interested in a way to manage prev/next navigation by type AND by language.

LeisureLarry’s picture

Subscribing

dvhung95’s picture

In the template.php , add the function below. Then, in a node, call the function THEME_prev_next_node($node, $node->type) to return array of prev/next nodes.

/**
* Previous / Next function for nodes, ordered by node creation date with the same language
*
* @param $current_node: node object or node id
* @param $node_types:  array of node types to query
*
* @return array
* 
*/
function THEME_prev_next_node($current_node = NULL, $node_types = array()) {
    // make node object if only node id given
    if (!is_object($current_node)) { $current_node = node_load($current_node->nid); }

    // make an array if string value was given
    if (!is_array($node_types)) { $node_types = array($node_types); }

    // previous
    $prev = db_select('node', 'n')
    ->fields('n',array('nid','title','created'))
    ->condition('n.status', 1,'=')
    ->condition('n.type', $node_types,'IN')
    ->condition('n.language', $current_node->language ,'=')
    ->condition('n.created', $current_node->created,'<')
    ->orderBy('created','DESC')
    ->range(0,1)
    ->execute()
    ->fetchAssoc();

    // next or false if none
    $next = db_select('node', 'n')
    ->fields('n',array('nid','title','created'))
    ->condition('n.status', 1,'=')
    ->condition('n.type', $node_types,'IN')
    ->condition('n.language', $current_node->language ,'=')
    ->condition('n.created', $current_node->created,'>')
    ->orderBy('created','ASC')
    ->range(0,1)
    ->execute()
    ->fetchAssoc();

    return array('prev' => $prev, 'next' => $next);
}