• Resolved turbodb

    (@turbodb)


    Running Period Pro. (but version 1.07)

    I have added a custom taxonomy to my site called “Trip”. I’d like to use a different layout for it than the “Posts” layout, but when I go into the Customize: Layout settings, I have options for Posts, Pages, Blog, and Archive.

    Is there a way to add my custom taxonomy here? Or, is there a way to do the layout in PHP easily? I want to use the one column, wide layout when things are shown using this taxonomy.

    As it is, I’ve copied the contents of index.php into my taxonomy-trip.php file (in a child theme), so right now I’m just getting the same layout as… Archive I guess?

    Ultimately what I want to do here is to pull some metadata for the taxonomy item from the database and then show (in the loop-container) the various posts that are associated in the taxonomy item.

    Thanks!

    <?php get_header();
    
        get_template_part( 'content/archive-header' );
    
        do_action( 'after_archive_header' ); ?>
        <div>TRIP TEMPLATE</div>
        <div id="loop-container" class="loop-container">
            <?php
            if ( have_posts() ) :
                while ( have_posts() ) :
                    the_post();
                    ct_period_get_content_template();
                endwhile;
            endif;
            ?>
        </div>
    
    <?php
    
    the_posts_pagination( array(
        'prev_text' => esc_html__( 'Previous', 'period' ),
        'next_text' => esc_html__( 'Next', 'period' )
    ) );
    
    get_footer();
    
Viewing 5 replies - 1 through 5 (of 5 total)
  • Theme Author Ben Sibley

    (@bensibley)

    Thanks for using Period Pro!

    There isn’t a way to modify the layout via the Customizer for custom post types as of now, but a custom solution can be made.

    You’ll want to copy the sidebar-primary.php file into your child theme, and then add a conditional check at the top. Something like:

    if ( is_tax('trips') ) {
      return;
    }

    That way, if it is the trips taxonomy, the sidebar won’t be output.

    Then to apply the styles needed, add a filter on the body class, like this:

    function my_custom_body_class($classes) {
    
      if ( is_tax('trips') ) {
        $classes[] = 'narrow-layout';
      }
    
      return $classes;
    }
    add_filter( 'body_class', 'my_custom_body_class' );
    

    “narrow-layout” will give you a single column layout without a sidebar, and you can use “wide-layout” as well for the other single column design.

    • This reply was modified 4 years, 5 months ago by Ben Sibley.
    Thread Starter turbodb

    (@turbodb)

    Thanks Ben. Got me what I was looking for.

    I have a site plugin where I keep most of my extra stuff (similar to Period Pro). Is there a way for me to put this stuff in the site plugin, rather than override the theme files? (just for portability)…

    Theme Author Ben Sibley

    (@bensibley)

    The function I shared can be put into the plugin, no problem. The sidebar code would need to be added to sidebar-primary.php in the child theme, but I can share an alternate approach.

    I took this code from Period Pro and made some quick edits but I think you will get the idea. I haven’t tested it after the edits made here so please keep that in mind (there could be an error):

    // remove the sidebar if the current layout calls for it
    function example_function_remove_sidebar( $sidebars_widgets ) {
    
    	if ( is_tax( 'trips' ) ) {
    $sidebars_widgets['primary'] = false;
    	}
    
    	return $sidebars_widgets;
    }
    add_filter( 'sidebars_widgets', 'example_function_remove_sidebar' );

    That function can be dropped into your plugin and will remove the sidebar so you don’t have to use a child theme with the sidebar-primary.php file.

    Thread Starter turbodb

    (@turbodb)

    Great, that’s what I was looking for was that sidebars_widgets hook. Thanks Ben!

    Theme Author Ben Sibley

    (@bensibley)

    Awesome. Glad I could help!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Layout for custom taxonomy’ is closed to new replies.