0

我试图在单独的页面上列出一些游戏。在新窗口中打开游戏页面时,页面 ( < title>) 的标题设置为游戏页面标题 (< h1>我的游戏)。还要列出我正在使用快速选项卡的所有游戏类型。

从 12 种类型的游戏中,只有其中 2 种的标题是正确的,我的问题是我不知道它来自哪里。我已经尝试了var_dump()所有标题,并且所有标题都返回相同的东西“游戏”而不是来自 db 的标题/标题。

我应该在哪里看或下一步是什么?

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

我应该在哪里看或下一步是什么?

这是我的预处理页面代码

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

        }
    }
4

1 回答 1

1

您可以将 drupal_set_title(YOUR_TITLE) 用于不同的页面。

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

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

从主题级别,您可以在 template.php 中使用此代码:

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

对于 Drupal 7,它是:$vars['site_name']

于 2013-08-01T08:24:57.053 回答