douqian8238 2016-04-24 01:59
浏览 24
已采纳

如果页面无法回显自定义标题

i have a posttype to which i have a page templates assigned using plugin custom posttype page template, so that my posts having img attachments in the posttype are displayed using a particular template. In my header.php i have code

if ( is_page_template ( 'page-book.php' ) )
                { $currenturl=$_SERVER['REQUEST_URI'];
                  $booktitle = str_replace("http://mybooks.com/books/", "", $currenturl);
                  $booktitle = str_replace("-", " ", $booktitle);
                  $booktitle = strtoupper($booktitle);
                  echo $booktitle;
                }

but it echoes the url of the post in the title instead of the custom echo

how do i get it to echo the custom title

  • 写回答

2条回答 默认 最新

  • dongpiao8821 2016-04-24 03:16
    关注

    This line $currenturl = $_SERVER['REQUEST_URI']; of your code only return string that is part of the URL.

    For example, the given url http://mybooks.com/books/title it return /books/title and when you try to replace it with an empty string nothing is replace because str_replace function doesn't find a match.

    For you to get the trailing part of the url, you can use basename

    For example

    echo basename($currenturl);
    

    It will return the last part of the url and that is

    title.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 软件工程用例图的建立(相关搜索:软件工程用例图|画图)
  • ¥15 如何在arcgis中导出拓扑关系表
  • ¥15 处理数据集文本挖掘代码
  • ¥15 matlab2017
  • ¥15 在vxWorks下TCP/IP编程,总是connect()报错,连接服务器失败: errno = 0x41
  • ¥15 AnolisOs7.9如何安装 Qt_5.14.2的运行库
  • ¥20 求:怎么实现qt与pcie通信
  • ¥50 前后端数据顺序不一致问题,如何解决?(相关搜索:数据结构)
  • ¥15 基于蒙特卡罗法的中介效应点估计代码
  • ¥15 罗技G293和UE5.3