我正在使用谷歌分析模块来检索过去一天在我的网站上最受欢迎的文章,以填充“趋势”块。
问题是PageTitle字段来自元数据,并且包括管道和站点名称。我想把它从字符串的末尾去掉,但是我不知道如何使用rewrite results在视图中做到这一点。
我创建了一个views-view-field--pageTitle.tpl.php文件,并将其编辑为:
<?php
$output = str_replace(" | My Site", "", $output);
print $output;
?>这似乎行不通..。
发布于 2017-11-17 03:52:18
在template.php中使用a预处理器肯定行得通。还有其他选项可以更改页面,但这取决于您使用什么模块和什么设置来生成标题,显然是使用了某个地方定义模式,所以不知道我的建议是使用这样的预处理器
function THEME_NAME_preprocess_page(&$variables) {
//you could use arg to identify your page page
//https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/arg/7.x
// if the page is the one you are looking then override the title
drupal_set_title('mytitle');
}发布于 2017-11-17 18:15:28
我认为您必须在template.php中修改元数据,因此您可以使用:
THEMENAME_html_head_alter(&$head_elements) {
// dump content of $head_elements and find your value to modify
}您还可以使用元数据模块来处理meta:https://www.drupal.org/project/metatag
希望它能有所帮助;)
发布于 2017-11-17 02:11:19
如果你确定它总是以My Article Title | My Web Site的形式返回,你可以在|处拆分字符串。
$result = "My Article Title | My Web Site"; //the string that was returned
$splitResult = explode(" | ", $result); //split the string at " | ", creating an array: ["My Article Title", "My Web Site"]
$articleTitle = $splitResult[0]; //get the first item in the arrayhttps://stackoverflow.com/questions/47336298
复制相似问题