WordPress :查找类别 link
WordPress : Look up a category link
我尝试在 WordPress 中获取 class 页面的 link。
http://localhost:8888/Scriptura/ScripturaForWordpress/category/a-category/
我试过了,但没有成功:
get_category_link( is_category() );
如何进行?
get_category_link()
需要category_id
作为参数。你可以这样说:
get_category_link(get_cat_ID( $cat_name ));
最后我找到了一个解决方案,但是 WordPress 在这个问题上困扰着我,所以我采用了一个解决方法:
$uri = '//' .$_SERVER[ 'HTTP_HOST' ] . $_SERVER[ 'REQUEST_URI' ]; // Alternative to get_permalink() does not work in all situations. In real life this variable is global.
$arrayHttp = [ 'http://', 'https://' ]; // Here it's not very nice, is to prepare the str_replace that follows ...
$testLink = ( $tabUri == $uri );
foreach ( ( array ) $menu_items as $key => $menu_item ) {
$title = $menu_item->title;
$tabUri = $menu_item->url; // It retrieves the URL of the tab
$tabUri = str_replace( $arrayHttp, '//', $tabUri ); // Treatment allows for comparison with the variable $url. If you have a solution for dealing with HyperText Transfer Protocol in a more elegant way, I'm interested ...
// Following the foreach...
}
我尝试在 WordPress 中获取 class 页面的 link。
http://localhost:8888/Scriptura/ScripturaForWordpress/category/a-category/
我试过了,但没有成功:
get_category_link( is_category() );
如何进行?
get_category_link()
需要category_id
作为参数。你可以这样说:
get_category_link(get_cat_ID( $cat_name ));
最后我找到了一个解决方案,但是 WordPress 在这个问题上困扰着我,所以我采用了一个解决方法:
$uri = '//' .$_SERVER[ 'HTTP_HOST' ] . $_SERVER[ 'REQUEST_URI' ]; // Alternative to get_permalink() does not work in all situations. In real life this variable is global.
$arrayHttp = [ 'http://', 'https://' ]; // Here it's not very nice, is to prepare the str_replace that follows ...
$testLink = ( $tabUri == $uri );
foreach ( ( array ) $menu_items as $key => $menu_item ) {
$title = $menu_item->title;
$tabUri = $menu_item->url; // It retrieves the URL of the tab
$tabUri = str_replace( $arrayHttp, '//', $tabUri ); // Treatment allows for comparison with the variable $url. If you have a solution for dealing with HyperText Transfer Protocol in a more elegant way, I'm interested ...
// Following the foreach...
}