Skip to main content

Showing Brizy Template based on an ACF field

Comments

5 comments

  • Permanently deleted user

    Hello Sam,

    Thank you for contacting us.

    That code takes a page id and builds only the HTML of the head body footer popups etc, in reality, to render a page it is not only that code some multiple actions and functions have their part of the work for example the js and css scripts is responsible this code Brizy_Public_AssetEnqueueManager::_init()->enqueuePost( Brizy_Editor_Post $post ); and so on. 
We do not recommend using any functions or hooks of the plugin until our API is ready. I would recommend you to use some WordPress functions like add_shortcode and keep these in the child theme so our plugin updates will not damage any of yours functionally. 
At the moment there is only this solution once we release the API which is in development then you will have much more freedom.

    Best regards, Nelea.

     

    0
  • Sam Cohen

    Ok, Nelea.

    Thanks for your response. I have this question:
    If I make a custom single-listing page with "listings" being my CPT and I made 2 different brizy templates, without any conditions. Could I essentially show a template based on an ACF field using the example code in my previous message?

    For example:

    /**** for single-listing.php ****/
    $post_id = get_the_ID();
    if(get_field('pagetype', $post_id) == 'type1'):
    get_brz_page_template(1545); //type1 brizy template post id
    else:
    get_brz_page_template(1549); //type2 brizy template post id
    endif;


    /**** for functions.php *****/
    function get_brz_page_template($id){
    if(!$id)
    return

    $brz_editor_post_id = $id;
    $brz_post_id = Brizy_Editor_Post::get( $brz_editor_post_id ); $brz_html = new Brizy_Editor_CompiledHtml( $brz_post_id->get_compiled_html() ); // the <head> content // the $headHtml contains all the assets the page needs $headHtml = apply_filters( 'brizy_content', $brz_html->get_head(), Brizy_Editor_Project::get(), $brz_post_id->getWpPost() ); // the <body> content $bodyHtml = apply_filters( 'brizy_content', $brz_html->get_body(), Brizy_Editor_Project::get(), $brz_post_id->getWpPost() );

    return $headHtml.$bodyHtml;
    }
    0
  • Permanently deleted user

    Hi

    Sorry for the late reply, support is limited on weekends.

    Maybe a better solution would be to create two post types and two Brizy templates and link every template to one of these custom post types. 
Another solution is to create two templates and link them with a taxonomy that you can choose in the listings. For example, will name the taxonomy listings-tax that have terms like Term A and Term B attach some listings to Term A and others to B, and in the templates conditions you choose for one template Term A and for the second template choose Term B.
Or you can try something like this:

    <?

    /**** for functions.php *****/

    function get_brz_page_template( $id ) {




        $compiled = Brizy_Editor_Post::get( $id )->get_compiled_page();

        $pid      = Brizy_Editor::get()->currentPostId();

    // the <head> content

    // the $headHtml contains all the assets the page needs

        $headHtml = apply_filters( 'brizy_content', $compiled->get_head(), Brizy_Editor_Project::get(), $pid );

    // the <body> content

        $bodyHtml = apply_filters( 'brizy_content', $compiled->get_body(), Brizy_Editor_Project::get(), $pid );




        return $headHtml . $bodyHtml;

    }




    ?>

    <!DOCTYPE html>

    <html <?php language_attributes(); ?>>

    <head>

        <meta charset="<?php bloginfo( 'charset' ); ?>">

        <link rel="profile" href="http://gmpg.org/xfn/11">

        <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">

        <?php

        if ( ! current_theme_supports( 'title-tag' ) ) {

            echo '<title>' . wp_get_document_title() . '</title>';

        }




        wp_head();

        ?>

    </head>

    <body <?php body_class(); ?>>

    <?php

        do_action( 'wp_body_open' );




        $post_id = get_the_ID();




        if ( get_field( 'pagetype', $post_id ) == 'type1' ):

            add_action( 'wp_enqueue_scripts', function () use ( $post_id ) {

                Brizy_Public_AssetEnqueueManager::_init()->enqueuePost( Brizy_Editor_Post::get( 1545 ) );

            }, 9999 );

            get_brz_page_template( 1545 ); //type1 brizy template post id

        else:

            add_action( 'wp_enqueue_scripts', function () use ( $post_id ) {

                Brizy_Public_AssetEnqueueManager::_init()->enqueuePost( Brizy_Editor_Post::get( 1549 ) );

            }, 9999 );

            get_brz_page_template( 1549 ); //type2 brizy template post id

        endif;




        wp_footer();

    ?>

    </body>

    </html>







    <?
    /**** for functions.php *****/
    function get_brz_page_template( $id ) {

    $compiled = Brizy_Editor_Post::get( $id )->get_compiled_page();
    $pid = Brizy_Editor::get()->currentPostId();
    // the <head> content
    // the $headHtml contains all the assets the page needs
    $headHtml = apply_filters( 'brizy_content', $compiled->get_head(), Brizy_Editor_Project::get(), $pid );
    // the <body> content
    $bodyHtml = apply_filters( 'brizy_content', $compiled->get_body(), Brizy_Editor_Project::get(), $pid );

    return $headHtml . $bodyHtml;
    }

    ?>
    <!DOCTYPE html>
    <html <?php language_attributes(); ?>>
    <head>
    <meta charset="<?php bloginfo( 'charset' ); ?>">
    <link rel="profile" href="http://gmpg.org/xfn/11">
    <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
    <?php
    if ( ! current_theme_supports( 'title-tag' ) ) {
    echo '<title>' . wp_get_document_title() . '</title>';
    }

    wp_head();
    ?>
    </head>
    <body <?php body_class(); ?>>
    <?php
    do_action( 'wp_body_open' );

    $post_id = get_the_ID();

    if ( get_field( 'pagetype', $post_id ) == 'type1' ):
    add_action( 'wp_enqueue_scripts', function () use ( $post_id ) {
    Brizy_Public_AssetEnqueueManager::_init()->enqueuePost( Brizy_Editor_Post::get( 1545 ) );
    }, 9999 );
    get_brz_page_template( 1545 ); //type1 brizy template post id
    else:
    add_action( 'wp_enqueue_scripts', function () use ( $post_id ) {
    Brizy_Public_AssetEnqueueManager::_init()->enqueuePost( Brizy_Editor_Post::get( 1549 ) );
    }, 9999 );
    get_brz_page_template( 1549 ); //type2 brizy template post id
    endif;

    wp_footer();
    ?>
    </body>
    </html>

    <?
    /**** for functions.php *****/
    function get_brz_page_template( $id ) {

    $compiled = Brizy_Editor_Post::get( $id )->get_compiled_page();
    $pid = Brizy_Editor::get()->currentPostId();
    // the <head> content
    // the $headHtml contains all the assets the page needs
    $headHtml = apply_filters( 'brizy_content', $compiled->get_head(), Brizy_Editor_Project::get(), $pid );
    // the <body> content
    $bodyHtml = apply_filters( 'brizy_content', $compiled->get_body(), Brizy_Editor_Project::get(), $pid );

    return $headHtml . $bodyHtml;
    }

    ?>
    <!DOCTYPE html>
    <html <?php language_attributes(); ?>>
    <head>
    <meta charset="<?php bloginfo( 'charset' ); ?>">
    <link rel="profile" href="http://gmpg.org/xfn/11">
    <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
    <?php
    if ( ! current_theme_supports( 'title-tag' ) ) {
    echo '<title>' . wp_get_document_title() . '</title>';
    }

    wp_head();
    ?>
    </head>
    <body <?php body_class(); ?>>
    <?php
    do_action( 'wp_body_open' );

    $post_id = get_the_ID();

    if ( get_field( 'pagetype', $post_id ) == 'type1' ):
    add_action( 'wp_enqueue_scripts', function () use ( $post_id ) {
    Brizy_Public_AssetEnqueueManager::_init()->enqueuePost( Brizy_Editor_Post::get( 1545 ) );
    }, 9999 );
    get_brz_page_template( 1545 ); //type1 brizy template post id
    else:
    add_action( 'wp_enqueue_scripts', function () use ( $post_id ) {
    Brizy_Public_AssetEnqueueManager::_init()->enqueuePost( Brizy_Editor_Post::get( 1549 ) );
    }, 9999 );
    get_brz_page_template( 1549 ); //type2 brizy template post id
    endif;

    wp_footer();
    ?>
    </body>
    </html>

     

     

    The code is not tested it is written on the fly so feel free to change it, for example you can remove $headHtml = apply_filters( 'brizy_content', $compiled->get_head(), Brizy_Editor_Project::get(), $pid ); and add it on the action wp_head. , and so on.

    0
  • Sam Cohen

    Thanks for your reply!!

    I love it when brizy support responds with code :D
    I take it that you have written 3 different solutions?

    I will definitely test these out!

    Just on a side note, I was able to use Post Formats with ACF and Brizy Templates!

    However, there is a bug in the Brizy Templates to only show Post format types as an option to include/exclude. They DO NOT show as an option unless there is an existing post made using a post format, strange.


    I would think that ALL post formats should show by default?

    0
  • Natalia Chitoroaga

    Hi Sam,

    Thank you for your message.

    Apologizes for this late reply, your last comment was received in nonreply@zendesk email address, aka spam folder.

    Yes, indeed. Brizy will not display all post format types, only those formats that have at least 1 post. 

    I created an issue for the team, they will fix this inconvenience.

     

    Regards, Natalia 

    0

Please sign in to leave a comment.