Reputation: 35
How can I add rel next and previous in drupal-7 term pages programmatically? and how important is rel for google?
some of my pages are listed here:
Upvotes: 1
Views: 64
Reputation: 598
there was no solution for it as a module i myself developed a module myself. i wish it could help you
first of all we user hook_preprocess_html and i checked if this page is a term page or not
if (arg(0) == 'taxonomy' && arg(1) == 'term') {
and then with use of page argument and function taxonomy_select_nodes you can find on what page your are and what is the next and prevoius page but one important this,
and there is no page with argument page=1, this is the first page
function your_theme_preprocess_html(&$variables) {
if (arg(0) == 'taxonomy' && arg(1) == 'term') {
$term = taxonomy_term_load(arg(2));
if( $_GET && $_GET['page'] && is_numeric(@$_GET['page']) ){
$prev = $_GET['page']-1;
$next = $_GET['page']+1;
$url = url('taxonomy/term/'.arg(2));
if( $_GET['page'] > 1 ){
$head_link = array(
'rel' => 'prev',
'href' => 'http://yourdomain.com'.$url.'?page='.$prev
);
drupal_add_html_head_link($head_link);
}
if( $_GET['page'] == 1 ){
$head_link = array(
'rel' => 'prev',
'href' => 'http://yourdomain.com'.$url
);
drupal_add_html_head_link($head_link);
}
$numbers = taxonomy_select_nodes( arg(2),true ,1000 );
if( count($numbers) > $next * 100 ){
$head_link = array(
'rel' => 'next',
'href' => 'http://yourdomain.com'.$url.'?page='.$next
);
drupal_add_html_head_link($head_link);
}
}
else {
$numbers = taxonomy_select_nodes( arg(2),true ,1000 );
if( count($numbers) > 100 ){
$url = url('taxonomy/term/'.arg(2));
$head_link = array(
'rel' => 'next',
'href' => 'http://yourdomain.com'.$url.'?page=1'
);
drupal_add_html_head_link($head_link);
}
}
}
}
this function taxonomy_select_nodes is really awesome, you give it "tid" of a term, it tells you how node is tagged with this term.
even you can add class to body with hook_preprocess_html
write all this code in template.php file in your theme
Upvotes: 2