我看到了一些删除最后一个;斜杠,但不是如何删除第一个和最后一个斜杠。
我尝试过:
$post_url_rel = wp_make_link_relative(get_permalink( $post_id ));
ltrim($post_url_rel, \'/\');
rtrim($post_url_rel, \'/\');
但还是写着postname/有人知道为什么这不起作用吗?
我看到了一些删除最后一个;斜杠,但不是如何删除第一个和最后一个斜杠。
我尝试过:
$post_url_rel = wp_make_link_relative(get_permalink( $post_id ));
ltrim($post_url_rel, \'/\');
rtrim($post_url_rel, \'/\');
但还是写着postname/有人知道为什么这不起作用吗?
因为你没有把ltrim()
和rtrim()
返回变量。这些函数返回修剪后的值,它们不修改传递的变量。因此,您需要这样做:
$post_url_rel = wp_make_link_relative(get_permalink( $post_id ));
$post_url_rel = ltrim($post_url_rel, \'/\');
$post_url_rel = rtrim($post_url_rel, \'/\');
或者更好的是,使用trim()
, 这将从两端移除它:$post_url_rel = wp_make_link_relative(get_permalink( $post_id ));
$post_url_rel = trim($post_url_rel, \'/\');
我的主题中有一个自定义函数,可以创建动态sitemap.xml 文件我用的是$myVar = get_posts( array(...) ). 在该数组中,我需要排除一些页面。我想排除某些父页面及其所有子页面。我只想使用父页面slug来获取父页面和子页面的所有ID的数组。问题是:\'exclude\' => 在array() 仅接受ID数组。不是鼻涕虫。如何通过某种函数(或其他方式)通过父页面slug返回ID数组(包括父ID及其所有子项)来实现它?例如,假设父页面slug是abc.谢谢你了。