drupal 术语 pagas 中没有 rel="next" 和 rel="prev"

There is no rel="next" and rel="prev" in drupal term pagas

如何以编程方式在 drupal-7 术语页中添加 rel next 和 previous? rel 对于 google 有多重要?

这里列出了我的一些页面:

کاردستی

سوپ ساده

عکس کودک

کاردستی

کاردستی

作为一个模块没有解决方案我自己开发了一个模块。 希望对你有帮助

首先我们用户hook_preprocess_html 我检查了这个页面是否是学期页面

if (arg(0) == 'taxonomy' && arg(1) == 'term') {

然后使用页面参数和函数 taxonomy_select_nodes 你可以找到你所在的页面以及下一页和上一页 但重要的是,

  • 第一页没有上一页
  • 上一页没有下一页
  • 并且没有参数page=1的页面,这是第一页

    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);
            }
        }
    
    }
    }
    

这个函数taxonomy_select_nodes真牛逼,你给它"tid"一个term,它告诉你节点是怎么用这个term标记的

甚至你可以用 hook_preprocess_html

将 class 添加到 body

将所有这些代码写入您主题的 template.php 文件中