【问题标题】:How to remove page title from the post title link?如何从帖子标题链接中删除页面标题?
【发布时间】:2017-10-04 10:35:06
【问题描述】:

我一直在使用 php 尝试获取帖子标题以链接到正确的帖子,但现在它不断在末尾添加页面名称。

<h6><a href="<?php the_permalink($this_post->ID); ?>" title="<?php 
the_title(); ?>"><?php the_title($this_post->post_title); ?></a></h6>

这是该页面的链接,因此您可以正确理解我的意思-http://www.city-perks.co.uk/discounts/

【问题讨论】:

  • 这个问题还不清楚。似乎 WP 正在做正确的事情。您希望问题和答案达到什么目的?
  • 所以标题现在链接到正确的帖子,但它在每个标题的末尾添加了“折扣”一词,我无法删除它。

标签: php wordpress


【解决方案1】:

试试这个代码

<?php
     if ($cmb_listing_layout == '3') 
     { 
         sprintf('<h6>%s</h6>', esc_attr($this_post->ID)); 
     } 
?>

如果你想获得另一个页面的标题,你需要使用get_the_title( $id_page )函数。

【讨论】:

  • 作为一个完整的白痴,我在问题中粘贴了错误的代码行。我现在已经更新了这个问题,所以也许它更有意义。
  • 谢谢,我显示了正确的标题,它只是出于某种原因在其末尾添加了 Discount 一词。
  • @RobDunn the_title 返回当前页面的标题。 Displays or returns the unescaped title of the current post
  • 对不起,我对 php 没有 100% 的信心。这是我认为可行的方法,但它仍然显示相同的问题。
    post_title) ; ? >
  • @RobDunn 这不起作用?我试图帮助你,但你说你是对的。
猜你喜欢
  • 2019-06-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-15
  • 2017-08-01
  • 2011-06-19
相关资源
最近更新 更多