【问题标题】:wordpress the_title will split [closed]wordpress the_title 将拆分[关闭]
【发布时间】:2013-09-09 11:27:10
【问题描述】:

你好,我正在 wordpress 上创建自己的主题,我想将 the_title() 函数拆分为数组,我想要的只是数组上的最后一项在 <span> 上,另一个在 <h1> 上。 我试过这个

$str = the_title();
$val = explode(" ", $str); // also tried implode
echo "<pre>";
print_r($val);
echo "</pre>";

但它只返回没有项目的数组 希望有人能帮助我。 这个我真的很想成为输出 &lt;h1&gt; This is a &lt;span&gt;Title&lt;/spam&gt;&lt;/h1&gt; 提前致谢

【问题讨论】:

  • 这个问题似乎是题外话,因为它是关于第三方软件的支持请求,这里是 Wordpress。对于这些,请首先使用供应商资源,例如 Wordpress Codex、Wordpress 支持论坛或其他专门针对该软件的支持资源。

标签: php html css wordpress


【解决方案1】:

不要使用the_title(),因为它会自动显示页面的当前标题。 在这个旁边使用$post-&gt;post_title;

让我们假设一个例句This is a Title

<?php
global $post;

$str = $post->post_title;
$exp = explode(" ",$str);

echo "<h1>".$exp[0].$exp[1].$exp[2];
echo "<span>".$exp[3]."</span></h1>";

?>

输出将是:

<h1>This is a<span>title</span></h1>

【讨论】:

    【解决方案2】:

    请使用 get_the_title() 而不是 the_title()。

    旁边是完整理解的链接:-- http://codex.wordpress.org/Function_Reference/get_the_title

    【讨论】:

      【解决方案3】:

      使用关注而不是$str = the_title();

      $str = get_the_title();
      
      -or-
      
      $str = the_title('', '', false);
      

      文档:http://codex.wordpress.org/Function_Reference/get_the_title

      【讨论】:

      • 解释 why 并链接到相关文档可以得到答案more useful
      猜你喜欢
      • 2014-04-06
      • 1970-01-01
      • 1970-01-01
      • 2014-12-22
      • 1970-01-01
      • 2015-10-12
      • 1970-01-01
      • 2018-03-30
      • 2016-11-20
      相关资源
      最近更新 更多