Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter taijj

    (@taijj)

    Thank you @rogierlankhorst, that is exactly what I needed! Works like a charm! ??

    You’re awesome! Thank you!

    Regards,
    T

    • This reply was modified 2 years, 4 months ago by taijj.
    Thread Starter taijj

    (@taijj)

    Hi @rogierlankhorst ,

    Thanks for the reply! I’m not using any plugin. I wrote the script, that uses ajax, myself and it’s part of my custom theme. If you get the impression that WordPress stuff is bypassed… that’s probably because it is.

    I’m not an experienced WordPress Dev, and made something like this for the first time.
    Here’s what I’m doing with ajax:

    Javascript

    
    function loadContent(id)
        {
            var data = { action: "tnet_load_post_content", pageId: id };
            useAjax(data, onContentLoaded); // Ajax call
        }
    
        function onContentLoaded(response)
        {
            var data = JSON.parse(response); // parse response
    
            contentContainer.html(data[0]); // Add parsed html to dedicated container
    
            // Do more stuff that WordPress does by default, but not for
            // HTML that was loaded in later with ajax
            addMissingStyles(data[1]);
            addMissingScripts();
            addProjectListeners();
            updateTabs();
            updateLanguageButtons();
            updateBackButtons();
            scrollToTop();
        }
    

    php

    //Load page into another page
        add_action( 'wp_ajax_tnet_load_post_content', 'tnet_load_post_content' );
        add_action( 'wp_ajax_nopriv_tnet_load_post_content', 'tnet_load_post_content' );
    
        function tnet_load_post_content() {
    
            $id = $_POST['pageId'];
            $meta = get_post_meta( $id, 'panels_data', true );
    
            if( class_exists( 'SiteOrigin_Panels' ) && $meta )
            {
                $renderer = SiteOrigin_Panels::renderer();
                $content = $renderer->render( $id );
                $css = $renderer->generate_css( $id );
            }
            else
            {
                $css = '';
                $content = apply_filters( 'the_content', get_page($id)->post_content );
            }
    
            echo json_encode(array($content, $css));
            die(); //<- will add a 0 in response, if not called!
        }

    If you got the time or need more details, I’ve even written a post about this topic here

    Any help would be greatly appreciated!

    Regards,
    T

    • This reply was modified 2 years, 4 months ago by taijj.
Viewing 2 replies - 1 through 2 (of 2 total)