dougan5772 2013-08-01 08:21
浏览 35
已采纳

Drupal SEO页面标题

I am trying to list a few games, each, on individual pages. While a game page is opened into a new window the head title of page (< title>) is set to games page header (< h1> My Game). Also to list all game types I am using quick tabs.

From 12 types of games only at 2 of them the title is settled correctly and my problem is that I don't know from where it comes. I have tried to var_dump() all the headers and all of them are returning the same thing "Game" not the title/heading from db.

Where should I look or what would be the next step ?

$metaTitle = $page['content']['metatags']['global']['title']['#attached']['metatag_set_preprocess_variable'][0][2];
$metaTitle = str_replace(' | SuperCasino.com', '', $metaTitle); 

Where should I look or what would be the next step ?

Here is my preprocess page code

function desktop_preprocess_page(&$vars, $hook) {
    if (isset($vars['node_title'])) {
        $vars['title'] = $vars['node_title'];
    }
    // Adding a class to #page in wireframe mode
    if (theme_get_setting('wireframe_mode')) {
        $vars['classes_array'][] = 'wireframe-mode';
    }
    // Adding classes wether #navigation is here or not
    if (!empty($vars['main_menu']) or !empty($vars['sub_menu'])) {
        $vars['classes_array'][] = 'with-navigation';
    }
    if (!empty($vars['secondary_menu'])) {
        $vars['classes_array'][] = 'with-subnav';
    }
    // Page template suggestions based off of content types
    if (isset($vars['theme_hook_suggestions']['node'])) {
        $vars['theme_hook_suggestions'][] = 'page__type__'. $vars['node']->type;
        $vars['theme_hook_suggestions'][] = "page__node__" . $vars['node']->nid;
    }

    // Add first/last classes to node listings about to be rendered.
    if (isset($vars['page']['content']['system_main']['nodes'])) {
        // All nids about to be loaded (without the #sorted attribute).
        $nids = element_children($vars['page']['content']['system_main']['nodes']);
        // Only add first/last classes if there is more than 1 node being rendered.
        if (count($nids) > 1) {
            $first_nid = reset($nids);
            $last_nid = end($nids);
            $first_node = $vars['page']['content']['system_main']['nodes'][$first_nid]['#node'];
            $first_node->classes_array = array('first');
            $last_node = $vars['page']['content']['system_main']['nodes'][$last_nid]['#node'];
            $last_node->classes_array = array('last');
        }
    }
    //var_dump($vars['theme_hook_suggestions']);die();

   // Page template suggestions based off URL alias
    if (module_exists('path')) {
        //$alias = drupal_get_path_alias(str_replace('/edit','',$_GET['q']));
        $alias = request_path();

        if ($alias != $_GET['q']) {
            //echo'here';die;
            $template_filename = 'page';
            foreach (explode('/', $alias) as $path_part) {
                $template_filename = $template_filename . '__' . str_replace('-','_',$path_part);
                $vars['theme_hook_suggestions'][] = $template_filename;
                //var_dump($template_filename);
            } 

        }
    }
  • 写回答

1条回答 默认 最新

  • duanheyi7147 2013-08-01 08:24
    关注

    You can use drupal_set_title(YOUR_TITLE) for the different pages.

        drupal_set_title($title = NULL, $output = CHECK_PLAIN)
    

    https://api.drupal.org/api/drupal/includes!bootstrap.inc/function/drupal_set_title/7

    From the theme level, you can use this code in your template.php:

    function MYTHEMENAME_preprocess_page(&$vars, $hook) {
        $vars['title'] = $custom_title';
        $vars['head_title'] = $custom_title;
    }
    

    For Drupal 7 its is : $vars['site_name']

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题