Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Genesis/Dynamik Members Navbar on CPT pages WordPress

  • SOLVED

Hi Guys


I have created a page template in Dynamik for my membership pages because I wanted to use a different navigation bar in the header.

So I created the template and added this filter which works great. I just create a page and assign it the members template and my sub navigation menu is displayed instead of the main navigation. Perfect.

<?php
add_action( 'genesis_after_header', 'genesis_do_subnav' );
genesis();
?>


However I have a couple of custom post types installed Library and Programmes and would like to show the sub navigation menu on those posts instead of the main navigation. But I cannot assign these post types the members template obviously

My question is how can I assign the sub navigation menu to my custom post types?

Answers (3)

2015-01-30

Kyle answers:

Hi Steve, try this in your functions.php file:

add_action( 'init', 'menu_by_cpt' );
function menu_by_cpt(){

global $post;
$type = get_post_type($post->ID);

if($type == 'library' OR $type == 'programmes'){
add_action( 'genesis_after_header', 'genesis_do_subnav' );
}
}


Kyle comments:

I feel like you might also need to do this in there to remove the standard nav:

remove_action( 'genesis_after_header', 'genesis_do_nav' );


Steve Watson comments:

Hi Kyle

Thanks for your reply.

That's not made any difference. I'm not sure how to troubleshoot it.


Kyle comments:

Few things to try and check:

-Change the init hook to genesis_header
-This is for single posts right?
-Did you update the $type parts with the exact slugs for the cpts? I didn't mention that


Steve Watson comments:

Hi Kyle

Ok I will try that. I'm not very familiar with hooks and filters.

I would like to assign the archive page for each post type the members template too.

http://iamnickwilliams.com/library/

http://iamnickwilliams.com/programmes

Plus all the cpt single posts

Does that make sense?


Steve Watson comments:

I'm not sure which parts to update to be honest. The slugs are library and programmes so I think you had it correct.

The change to genesis_header did not make a difference.

What bits do I need to update and try?

http://screencast.com/t/BMlBxAE5v


Kyle comments:

Let me try to recreate this locally and I'll get back to you


Kyle comments:

In the meantime did you try the other two posts suggestsion?

You would want to create these four files:

single-library.php
single-programme.php
archive-library.php
archive-programme.php

And make the template the same as you did for members, from there it would be automatic.


Steve Watson comments:

Hello Kyle

Sorry for the delay in getting back to you I was getting confused about this on the client site so decided to put together a test site so I could focus in on creating the single and archive templates for the post types "Talks" and "Programmes".

I have managed to create these templates but still need some help with the functions.

I need to show the members navigation in the header right widget area instead of the main navigation on both the single and archive pages of the two post types

I have not got a solution for this yet. I was thinking instead of using the header right with the custom menu widget I could reposition the main navigation using this process http://briangardner.com/reposition-primary-navigation/ then make the members menu the secondary navigation menu and create a function to replace the main with the secondary on the members cpt pages. Can you help with this?

I also need to show the members sidebar on both the single and archive pages of the two post types. I have managed to do this using the following functions but it does not successfully remove the Primary sidebar


// Swap sidebars on CPT pages
add_action('get_header','child_change_genesis_sidebar');
function child_change_genesis_sidebar() {
if ( is_singular('talks') || is_post_type_archive('talks') ) { // change 'post_type' to your CPT slug
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' ); //remove the default genesis sidebar
add_action( 'genesis_sidebar', 'child_do_cpt_sidebar' ); //add an action hook to call the function for my custom sidebar
}
}

// Output sidebar with the id 'sidebar-custom'
function child_do_cpt_sidebar() {
genesis_widget_area( 'members' );
}



I hope that all makes sense. I can do a video if it makes it easier for you.

http://stevewatsondemos.com/talks/ (archive)
http://stevewatsondemos.com/talks/talk-number-one/ (single)

You will see the primary sidebar has the meta widget and the members sidebar underneath has a calendar widget. The remove action does not seem to be working on the primary navigation.


Kyle comments:

Steve,

Try dynamic widgets instead of trying to add/remove the widget area all together.. it is more work than you need to do:

[[LINK href="https://wordpress.org/plugins/dynamic-widgets/"]]https://wordpress.org/plugins/dynamic-widgets/[[/LINK]]


Steve Watson comments:

Here's a quick video to show you what I've done. I hope it helps

http://screencast.com/t/eeRdhGEGbA5S

I'm happy to give you access to the site Kyle if you don't mind helping me out.


Steve Watson comments:

Here's a quick video to show you what I've done. I hope it helps

http://screencast.com/t/eeRdhGEGbA5S

I'm happy to give you access to the site Kyle if you don't mind helping me out.


Steve Watson comments:

I have widget logic already installed is that the same?

So are you saying that both my menu and sidebar challenges can be sorted with dynamic widgets?

Is that better than widget logic?


Kyle comments:

Widget logic will work. You can do something like

get_post_type() == 'talks'


Steve Watson comments:

Dynamic Widgets has done the job nicely... so much easier!!

thanks Kyle


Kyle comments:

Happy to help! Let me know if anything else pops up


Kyle comments:

Did you need anymore help here?


Steve Watson comments:

No I've nailed that now. Thanks

2015-01-30

Ian Lincicome answers:

You can solve your problem by making new template pages for the post types. All you have to do is rename the proper template files using the filename/-/post_type_name/file_ext method. In other words, for posts, you generally would make a copy of the single.php file and give it the name single-library.php and again repeat process to also create single-programmes.php. Then those custom post types will use the corresponding template files instead of the default single.php. Same thing can be done for any other template file such as archive.php would be come archive-library.php etc.... Let me know if this is enough to solve your problem of if you have additional questions. If you need more help, maybe just have me do it for you.


Ian Lincicome comments:

Maybe you should move on to the next solution;-)

2015-01-30

Romel Apuya answers:

create a template for the CPT's you have... Patterned from the members template

[[LINK href="http://codex.wordpress.org/Post_Types#Template_Files"]]http://codex.wordpress.org/Post_Types#Template_Files[[/LINK]]

template names for CPT

single posts of a custom post type will use single-{post_type}.php
and their archives will use archive-{post_type}.php