首页 文章

Wordpress wp_title()函数不适用于带有Warp Framework的Yootheme模板

提问于
浏览
0

我正在为我的wordpress网站使用Yootheme模板http://sribasu.com该主题基于Warp Framework构建 . 我的主题的head.php文件在连接bloginfo名称和wp_title()之后打印页面 Headers .

不幸的是,wp_title()函数没有生成任何输出 . 因此,我的所有内页和博客帖页都与主页具有相同的 Headers . 使用此函数时,warp框架是否有任何问题?

我正在使用wordpress 3.6 . 我一直试图搜索谷歌,看看它是否是一个常见的问题 . 但是还没找到合适的解决方案 . 请帮忙 .

编辑:head.php( /yoo_revista_wp/warp/systems/wordpress/layouts/head.php )的代码如下:

<meta charset="<?php bloginfo('charset'); ?>" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<?php if($this['config']->get('responsive', false)): ?>
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php endif; ?>
<title><?php bloginfo('name'); ?> <?php wp_title(); ?></title>
<link rel="shortcut icon" href="<?php echo $this['path']->url('template:favicon.ico');?>" />
<link rel="apple-touch-icon-precomposed" href="<?php echo $this['path']->url('template:apple_touch_icon.png'); ?>" />
<?php

wp_enqueue_script('jquery');
wp_head();

// set body classes
$this['config']->set('body_classes', implode(' ', get_body_class($this['config']->get('body_classes'))));

// get styles and scripts
$styles  = $this['asset']->get('css');
$scripts = $this['asset']->get('js');

// compress styles and scripts
if ($compression = $this['config']->get('compression')) {

    $options = array();
    $filters = array('CSSImportResolver', 'CSSRewriteURL', 'CSSCompressor');

    // set options
    if ($compression == 3) {
        $options['Gzip'] = true;
    }

    // set filter
    if ($compression >= 2 && ($this['useragent']->browser() != 'msie' || version_compare($this['useragent']->version(), '8.0', '>='))) {
        $filters[] = 'CSSImageBase64';
    }

    if ($styles) {
        // cache styles and check for remote styles
        $styles = array($this['asset']->cache('template.css', $styles, $filters, $options));
        foreach ($styles[0] as $style) {
            if ($style->getType() == 'File' && !$style->getPath()) {
                $styles[] = $style;
            }
        }
    }

    if ($scripts) {
        // cache scripts and check for remote scripts
        $scripts = array($this['asset']->cache('template.js', $scripts, array('JSCompressor'), $options));
        foreach ($scripts[0] as $script) {
            if ($script->getType() == 'File' && !$script->getPath()) {
                $scripts[] = $script;
            }
        }
    }

}

// add styles
if ($styles) {
    foreach ($styles as $style) {
        if ($url = $style->getUrl()) {
            printf("<link rel=\"stylesheet\" href=\"%s\" />\n", $url);
        } else {
            printf("<style>%s</style>\n", $style->getContent());
        }
    }
}

// add scripts
if ($scripts) {
    foreach ($scripts as $script) {
        if ($url = $script->getUrl()) {
            printf("<script src=\"%s\"></script>\n", $url);
        } else {
            printf("<script>%s</script>\n", $script->getContent());
        }
    }
}

// add feed link
if (strlen($this['config']->get('rss_url',''))) {
    printf("<link href=\"%s\" rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS 2.0\" />\n", $this['config']->get('rss_url'));
}

$this->output('head');

2 回答

  • 0

    我必须承认,从本的反应中得到了很好的线索 . 最后确定了罪魁祸首插件 - 它是Contus Video Gallery . 该插件很好用,但篡改了我的页面 Headers :X

    我在 /plugins/contus-video-gallery/hdflvvideoshare.php 的Contus Video Gallery插件中修复了wp_title过滤器功能,它就像一个魅力!

    以前的代码是:

    function add_video_title() {
        global $wpdb;
        $videoID            = url_to_custompostid(get_permalink());
        if (isset($_GET['p'])) {
            $videoID        = intval($_GET['p']);
        }
        if (isset($_GET['playid'])) {
            $playId         = intval($_GET['playid']);
        }
        if (!empty($videoID)) {
            $videoID        = $wpdb->get_var("SELECT vid FROM " . $wpdb->prefix . "hdflvvideoshare WHERE slug='" . intval($videoID) . "'");
            $video_title    = $wpdb->get_var("SELECT t1.name"
                            . " FROM " . $wpdb->prefix . "hdflvvideoshare AS t1"
                            . " WHERE t1.publish='1' AND t1.vid='" . intval($videoID) . "' LIMIT 1");
        }
        if (!empty($playId)) {
            $video_title    = $wpdb->get_var("SELECT t1.playlist_name AS name"
                            . " FROM " . $wpdb->prefix . "hdflvvideoshare_playlist AS t1"
                            . " WHERE t1.is_publish='1' AND t1.pid='" . intval($playId) . "' LIMIT 1");
        }
        if (!empty($video_title))
            echo $video_title;
    }
    

    现在代码是:

    function add_video_title($title) {
        if($_REQUEST['post_type']!='videogallery'){
            return $title;
        }
        global $wpdb;
        $videoID            = url_to_custompostid(get_permalink());
        if (isset($_GET['p'])) {
            $videoID        = intval($_GET['p']);
        }
        if (isset($_GET['playid'])) {
            $playId         = intval($_GET['playid']);
        }
        if (!empty($videoID)) {
            $videoID        = $wpdb->get_var("SELECT vid FROM " . $wpdb->prefix . "hdflvvideoshare WHERE slug='" . intval($videoID) . "'");
            $video_title    = $wpdb->get_var("SELECT t1.name"
                            . " FROM " . $wpdb->prefix . "hdflvvideoshare AS t1"
                            . " WHERE t1.publish='1' AND t1.vid='" . intval($videoID) . "' LIMIT 1");
        }
        if (!empty($playId)) {
            $video_title    = $wpdb->get_var("SELECT t1.playlist_name AS name"
                            . " FROM " . $wpdb->prefix . "hdflvvideoshare_playlist AS t1"
                            . " WHERE t1.is_publish='1' AND t1.pid='" . intval($playId) . "' LIMIT 1");
        }
        if (!empty($video_title))
            return $video_title;
    }
    
  • 0

    来自codex

    wp_title()函数不应该被主题与其他字符串或函数一起使用(比如与bloginfo('name')连接)来编写元素的内容,因为它会使插件无法重写整个 Headers 如果插件使用wp_title过滤器进行重写,这是最佳做法 . 现在,主题开发人员需要使用此功能 .

    测试代码:

    <?php bloginfo('name'); ?><?php wp_title('&raquo;'); ?>
    

    第一个参数$ sep:在帖子 Headers (即分隔符)之前或之后(由$ seplocation指定)显示的文本 . 默认值:»(»)

相关问题