我想在自定义菜单中添加BuddyPress“我最喜欢的主题”的链接。有没有办法在链接中使用当前登录用户的用户名?
我是说像%category%
在permalinks。
我想在自定义菜单中添加BuddyPress“我最喜欢的主题”的链接。有没有办法在链接中使用当前登录用户的用户名?
我是说像%category%
在permalinks。
是的,你有办法做到这一点。为了正确实施,我建议您阅读The Rewrite API: The Basics 文章特别注意Add Rewrite Tag 部分
您可以通过get\\u currentuserinfo()函数访问用户的显示名称。首先需要设置全局名称,然后才能访问显示名称。
<?php global $current_user;
get_currentuserinfo();
echo \'Hello, \' . $current_user->display_name . "\\n";
?>
EDIT: 抱歉,在回答之前没有注意到问题的日期。
function add_favorites_link( $items, $args ) {
// Check is user logged in
if ( is_user_logged_in() ) {
$user = wp_get_current_user();
$ID = $user->ID;
$fav = \'<a href="\'.bbp_get_favorites_permalink( $ID ).\'">Favorites</a>\';
// Change the Menu Location to yours
if ( $args->theme_location == \'primary\' ) {
$items .= \'<li>\'.$fav.\'</li>\';
}
return $items;
}
}
add_filter( \'wp_nav_menu_items\', \'add_favorites_link\', 10, 2 );
这是一个肮脏的解决办法,但它会让你开始。我用的是buddypress主题buddyboss. 主要原因是这个主题能够管理一个图片库(效果很好)。现在我想在members循环中调用picture函数。buddyboss的一位管理员告诉我:“您需要buddy\\u boss\\u pics.php中的函数。具体来说,您需要从第285行开始使用函数buddyboss\\u pics\\u screen\\u picture\\u grid\\u content()。您需要编辑文件以使用members循环,因为它当前使用的是displayed\\u u