Skip to:
Content
Pages
Categories
Search
Top
Bottom

Must I set up subnav items when creating a new component?

  • @henrywright-1

    Member

    Hi all

    Are subnav items mandatory when creating a new component?

    I just need the one page (a main nav item) as in:

    example.com/members/username/component-name

    I don’t need any subnav items such as

    example.com/members/username/component-name/sub-page

    Not entirely sure I can have what I want here – seems as though you must have a subnav item too? Hoping someone can throw some light on this…

Viewing 21 replies - 1 through 21 (of 21 total)
  • @modemlooper

    Moderator

    Nope. You create subnavs by declaring a parent on a nav item

    @henrywright-1

    Member

    @modemlooper – Great stuff, as in doing this?

    $nav = array(
    	'name' 		      => __( 'Component name', 'bp-component-name' ),
    	'slug' 		      => 'component-name',
    	'position' 	      => 80,
            'screen_function'     => 'bp_component_blah'
    );

    This does give the page I need:

    example.com/members/username/component-name

    Although this leads on to another problem – pagination. I’m displaying a list of posts on that page. paginate_links() is outputting nicely but when I visit the following nothing appears

    example.com/members/username/component-name/page/2
    example.com/members/username/component-name/page/3

    That said, I can get pagination to work when I introduce a subnav item:

    example.com/members/username/component-name/subpage/page/2
    example.com/members/username/component-name/subpage/page/3

    I just don’t want the subnav item in there. any ideas?

    @modemlooper

    Moderator

    page as subnav but leave subnav name blank?

    ‘name’ => __( ‘Component name’, ‘bp-component-name’

    ‘name’ => __( ”, ‘bp-component-name’

    @henrywright-1

    Member

    @modemlooper not sure I follow?

    @modemlooper

    Moderator

    I did this once in the past and it was basically a hack.

    leave the name of the subnav empty so it doesn’t show on profile. Not sure it will work you can also hide via css but thats lame.

    @henrywright-1

    Member

    @modemlooper ah yes I see! – I suppose if it works, why not 🙂

    @modemlooper

    Moderator

    bp_current_component
    bp_current_action
    bp_action_variables

    The url structure is

    members/user/bp_current_component/bp_current_action/bp_action_variables

    I wrote something which I can’t remember to read the action variable and then displayed posts page/

    @modemlooper

    Moderator

    This is useful to dump everything $bp has on a given page.

    function bp_dump() {
    	global $bp;
    
    	foreach ( (array)$bp as $key => $value ) {
    		echo '<pre>';
    		echo '<strong>' . $key . ': </strong><br />';
    		print_r( $value );
    		echo '</pre>';
    	}
    	die;
    }
    add_action( 'wp', 'bp_dump' );

    @henrywright-1

    Member

    I suppose my problem comes down to why paginated posts are only displayed when a subnav is specified.

    e.g. If I display my list of posts on page

    members/username/COMPONENT-NAME/

    then i’d want my paginated posts to display like this:

    members/username/COMPONENT-NAME/page/2

    As it stands, i’m displaying my list of posts on:

    members/username/COMPONENT-NAME/

    and my paginated posts are available like this:

    members/username/component-name/SUBPAGE/page/2

    @henrywright-1

    Member

    bp_dump() V useful thanks – just taking a look through now…

    @modemlooper

    Moderator

    what name for component and subpage?

    @henrywright-1

    Member

    @modemlooper

    bp_current_component
    bp_current_action
    bp_action_variables

    members/user/bp_current_component/bp_current_action/bp_action_variables

    So bp_current_component is the main nav item, bp_current_action is the subnav item and bp_action_variables is what comes after that.

    bp_dump() shows me that when bp_current_action has a value, pagination works. When it doesn’t have a value (e.g. I don’t have a subnav item), although paginate_links() outputs the proper URLs, when I visit the URL I just get redirected to the members directory. It’s almost like the query doesn’t contain the post information.

    @modemlooper

    Moderator

    it seems if you put a space as the tab name it works.

    posts/page/2

    make subnav page but put a space as the name so it doesn’t show as a subnav but then you can tap into action variable

    @henrywright-1

    Member

    actually – it only seems to work when a bp_current_action (subnav item) is set. strange!

    EDIT: Oh right, i’ll give the space a shot…

    @henrywright-1

    Member

    @modemlooper tried the space, it didn’t work very well for me.

    looking through BP core – i noticed every single component has a subnav set – even BP Follow has subnavs set – it’s making me think subnavs (bp_current_actions) are needed as the BP Follow subnavs are highly redundant:

    members/username/following/following
    members/username/followers/followers

    @modemlooper

    Moderator

    yeah but you want to hide the subnav. To tap into the action variable you need a current action and that’s created with a nav item.

    https://gist.github.com/modemlooper/7111457

    @henrywright-1

    Member

    @modemlooper got ya! I see now – perhaps the pagination needs the actions variables to be available. Hiding the subnav (but still keeping it) works.

    Thanks for all your help in this thread, appreciate it! 🙂

    Now i’m off to learn about why this blasted pagination query needs the action variables in order to work…

    @modemlooper

    Moderator

    you need some way of knowing what page you are on and using uri to get a page number is the best way and it works like WP pagination.

    bp_action_variables are stored as an array so it’s easy to tap into:

    posts/page/2/3/4

    $bp->action_variables[0] == 2
    $bp->action_variables[1] == 3
    $bp->action_variables[2] == 4

    So if you did a front end editing of a post you could do

    posts/post/2/edit

    do an if ( $bp->action_variables[1] == ‘edit’ )

    then display an edit screen instead of the normal post screen

    @henrywright-1

    Member

    bp_action_variables are stored as an array

    That does make it easy. you just have to ‘catch’ them right?

    so if somebody randomly entered the URL posts/page/2/3/hello and I did something like

    if ( $bp->action_variables[2] == 'hello' ) {
    // do something
    } else {
    // do nothing
    }

    then ‘do something’ would happen

    @modemlooper

    Moderator

    Exactly.

    So in your code to pull posts you can supply the paged # from $bp->action_variables[0]

    $query = new WP_Query( array( 'paged' => $bp->action_variables[0] ) );

    @henrywright-1

    Member

    sweet! thanks again for the help

Viewing 21 replies - 1 through 21 (of 21 total)
  • The topic ‘Must I set up subnav items when creating a new component?’ is closed to new replies.
Skip to toolbar