0

我正在为我的 wordpress 网站http://sribasu.com使用 Yootheme 模板。 该主题建立在 Warp 框架上。我的主题的 head.php 文件在连接 bloginfo 名称和 wp_title() 后打印页面标题。

不幸的是, wp_title () 函数没有产生任何输出。结果,我所有的内页和博客文章页面都与主页具有相同的标题。使用此功能时,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');
4

2 回答 2

1

来自法典

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

测试代码:

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

第一个参数,$sep:在(由$seplocation 指定)帖子标题(即分隔符)之前或之后显示的文本。默认: ” (”)

于 2013-08-21T18:36:48.007 回答
0

我必须承认,从 Ben 的回答中得到了很好的线索。最后确定了罪魁祸首插件 - 它是 Contus Video Gallery。该插件的功能很好,但篡改了我的页面标题:X

我在/plugins/contus-video-gallery/hdflvvideoshare.php的 Contus 视频库插件中修复了 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;
}
于 2013-08-21T20:38:12.737 回答