我有了一堆帖子全部被格式化为像这样设置WordPress的标题为两个独立的变量
Artist - Song Title
例如自定义后类型
The Smashing Pumpkins - Quiet
我试图把“艺术家”在变量$艺术家和'歌曲标题'中的一个变量$歌曲
$artistsong = get_the_title();
$songeach = explode("-", $artistsong);
$artist = $songeach[0];
$song = $songeach[1];
但是这不起作用。回声荷兰国际集团$艺术家得到完整的标题
The Smashing Pumpkins - Quiet
和呼应$歌无法正常输出
这个作品,如果我只是从纯文本出发,但与“get_the_title()”
$song = "The Smashing Pumpkins - Quiet";
$songeach = explode("-", $song);
$artist = trim($songeach[0]);
$song = trim($songeach[1]);
echo $artist;
//echos 'The Smashing Pumpkins'
echo $song;
//echos 'Quiet'
有没有另一种方法可以将完整的标题放入一个最初的变量,而不是get_the_title(),它似乎不适合我,或者我错过了其他的东西?
你确定这是一个“破折号”字符,而不是像“–”或“—”这样的东西吗? –
你插入这个代码的地方? –
Marc B - 我echo'd get_the_title()并复制了我的代码编辑器中提供的短划线。 – bbruman