This is searchable archive of our old support forums, which operated from 2012 - 2016. To find out how to get support for your current theme, please visit our support page.

How to apply custom layouts to custom post types, based on logged-in user

  • Creator
    Topic
  • #23585
    ajvanliere
    Member

    Hi, I want a custom post type to use one template when the user is logged in and another when they are not logged in. How can I achieve this?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
    Replies
  • #23593
    Jason Bobich
    Keymaster

    Hello,

    What do you mean when you say template? Are you talking about templates built with our layout builder? Are you using Theme Blvd Layouts to Posts plugin to attach them to posts? Or, do you mean WordPress theme template files, in general? Or something else maybe?

    #23617
    ajvanliere
    Member

    Hi,

    Yes I am talking about templates built with the layout builder.

    #23627
    Jason Bobich
    Keymaster

    Apologies, but there is no feature in the theme for this and would be a customization you’d need to make from your child theme.

    I would suggest looking into utilizing the filter themeblvd_frontend_config — Basically, every time a page loads on your site, the theme builds this array of data that is then referenced throughout several places. This includes determining if a custom layout is used and what that is.

    It will be helpful to look at how this array is built and where that filter is applied, so you know how to work it from your child theme’s functions.php. You can find this filter applied in /framework/includes/class-tb-frontend-init.php of the theme.

    The Theme Blvd Layouts to Posts plugin is actually a great example of something you can look at, that is already doing something similar to what you want to do. You should check it out, and how it assigns custom layouts to posts, when normally the theme is only adding them to pages based on an assigned page template.

    https://github.com/themeblvd/theme-blvd-layouts-to-posts/blob/master/tb-layouts-to-posts.php

    You’ll see the plugin first filters in the custom layout to themeblvd_frontend_config. You’ll obviously have your own logic here in terms of assigning whatever layout, based on the current user.

    https://github.com/themeblvd/theme-blvd-layouts-to-posts/blob/master/tb-layouts-to-posts.php#L54

    And then once the layout has been set to the frontend config, you then need to redirect to the custom layout page template.

    https://github.com/themeblvd/theme-blvd-layouts-to-posts/blob/master/tb-layouts-to-posts.php#L58

    #23670
    ajvanliere
    Member

    Awesome, that worked great, thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.