簡體   English   中英

如何獲取當前的Buddypress頁面名稱?

[英]How to get current Buddypress page name?

我正在嘗試動態顯示Buddypress中用戶所在頁面的名稱。 例如,如果您在“通知”頁面上,則需要一個顯示“通知”的變量。

我正在尋找可以正常工作的東西,例如the_title();。 用於Wordpress。

<?php echo (bp_current_component());?>

這可能會成功。

如果您需要header.php文件標簽的完整代碼,則可以使用下面給出的代碼。(您隨時可以根據需要進行自定義)

<title>

    <?php if ( is_home() ) { ?><? bloginfo('name'); ?>&nbsp;|&nbsp;<?php bloginfo('description'); ?><?php } ?>

    <?php if ( is_search() ) { ?><? bloginfo('name'); ?>&nbsp;|&nbsp;Search Results<?php } ?>

    <?php if ( is_author() ) { ?><? bloginfo('name'); ?>&nbsp;|&nbsp;Author Archives<?php } ?>

    <?php if ( is_single() ) { ?><?php wp_title(''); ?>&nbsp;|&nbsp;<? bloginfo('name'); ?><?php } ?>

    <?php if ( is_page() ) { ?><? bloginfo('name'); ?>&nbsp;|&nbsp;<?php wp_title(''); ?><?php } ?>

    <?php if ( is_category() ) { ?><? bloginfo('name'); ?>&nbsp;|&nbsp;Archive&nbsp;|&nbsp;<?php single_cat_title(); ?><?php } ?>

    <?php if ( is_month() ) { ?><? bloginfo('name'); ?>&nbsp;|&nbsp;Archive&nbsp;|&nbsp;<?php the_time('F'); ?><?php } ?>

    <?php if (function_exists('is_tag')) { if ( is_tag() ) { ?><? bloginfo('name'); ?>&nbsp;|&nbsp;Tag Archive&nbsp;|&nbsp;<?php  single_tag_title("", true); } } ?>

    <?php echo bp_get_displayed_user_fullname();?>&nbsp;|&nbsp;<?php echo ucfirst(bp_current_component());?>

</title>

那就是我網站的代碼,所以您可能想為您自定義

查看BuddyPress模板標簽參考

在那里您會找到諸如bp_is_messages_conversation()bp_is_change_avatar()函數。

這些可以這樣使用:

if ( bp_is_change_avatar() ) {
    // You are currently viewing the change avatar screen
} else {
    // You are not viewing the change avatar screen
}

關於通知,我不確定是否有“包裝器”功能可用,但是您可以執行以下操作:

if ( bp_is_current_action( 'unread' ) ) {
    // You are viewing the unread notifications screen
}

要么:

if ( bp_is_current_action( 'read' ) ) {
    // You are viewing the read notifications screen
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM