programing

페이지로 Visual Composer 단축 코드 렌더링

sourcejob 2023. 4. 4. 21:15
반응형

페이지로 Visual Composer 단축 코드 렌더링

하려고 합니다.echo시각 작곡가shortcodes페이지를 표시합니다.

아래 두 가지 방법을 모두 시도해 봤지만 효과가 없습니다.

기능들.php:

방법 1

/*
 * add shortcode file
 */
function include_file($atts) {
    $a = shortcode_atts( array(
        'slug' => 'NULL',
    ), $atts );

    if($slug != 'NULL'){
        ob_start();
        get_template_part($a['slug']);
        return ob_get_clean();
    }
}
add_shortcode('include', 'include_file');

방법 2

function someshortocode_callback( $atts = array(), $content = null ) {

    $output = "[vc_section full_width=\"stretch_row\" css=\".vc_custom_1499155244783{padding-top: 8vh !important;padding-bottom: 5vh !important;background-color: #f7f7f7 !important;}\"][vc_row 0=\"\"][vc_column offset=\"vc_col-lg-offset-3 vc_col-lg-6 vc_col-md-offset-3 vc_col-md-6\"][/vc_column][/vc_row][/vc_section]";
    return $output;
}
add_shortcode('someshortocode', 'someshortocode_callback');

file_filename_vc_shortcodes.php:

방법 1

<?php if ( is_plugin_active( 'js_composer/js_composer.php' ) ) {
    wc_print_notice('js_composer plugin ACTIVE', 'notice');
    echo do_shortcode('[include slug="vc_templates/shop-page"]');
}; ?>

결과

  • js_composer 플러그인 ACTIVE
  • 쇼트코드는 페이지상에 괄호로 둘러싸여 있습니다.

방법 2

<?php $post = get_post();

if ( $post && preg_match( '/vc_row/', $post->post_content ) ) {
// Visual composer works on current page/post
    wc_print_notice('VC ON', 'notice');
    echo add_shortcode('someshortocode', 'someshortocode_callback');
} else {
    wc_print_notice('VC OFF', 'notice');
    //echo do_shortcode('[include slug="vc_templates/shop-page"]');
}; ?>

결과

  • VC OFF(분명히 다음부터)vc_row숏코드는 없습니다)
  • 쇼트 코드가 페이지에 없습니다.

숍 페이지php

<?php
/**
Template Name:  Shop Page in theme
Preview Image:  #
Descriptions:   #
 * [vc_row][vc_column][/vc_column][/vc_row]
 */
?>
[vc_section full_width="stretch_row" css=".vc_custom_1499155244783{padding-top: 8vh !important;padding-bottom: 5vh !important;background-color: #f7f7f7 !important;}"][vc_row 0=""][vc_column offset="vc_col-lg-offset-3 vc_col-lg-6 vc_col-md-offset-3 vc_col-md-6"][/vc_column][/vc_row][/vc_section]

렌더링 가능합니까?vc shortcodes어떻게 할 수 있을까요?

사용방법:

WPBMap::addAllMappedShortcodes();

그럼 여느 때처럼do_shortcode($content);

즉, 성능으로 인한 페이지 빌더는 필요하지 않는 한 쇼트 코드를 등록하지 않습니다.

요소를 등록하는 경우vc_map또는vc_lean_map사용할 필요가 없습니다.add_shortcode이 기능을 사용하면 모든 것을 할 수 있습니다.WPBMap::addAllMappedShortcodes();렌더링 프로세스 중에 쇼트 코드클래스 콜백을 호출하고 다음으로 쇼트 코드템플릿을 호출합니다

Method 2에 대해서

사용하셔야 합니다.do_shortcode()숏코드 함수로 설정합니다.

function someshortocode_callback( $atts = array(), $content = null ) {
    $output = '[vc_section full_width="stretch_row" css=".vc_custom_1499155244783{padding-top: 8vh !important;padding-bottom: 5vh !important;background-color: #f7f7f7 !important;}"][vc_row 0=""][vc_column offset="vc_col-lg-offset-3 vc_col-lg-6 vc_col-md-offset-3 vc_col-md-6"]column text[/vc_column][/vc_row][/vc_section]';

    return do_shortcode( $output );
}

add_shortcode( 'someshortocode', 'someshortocode_callback' );

테스트 사이트의 작업 예: http://test.kagg.eu/46083958-2/

페이지만 포함[someshortocode]. 위의 코드가 에 추가되었습니다.functions.php.

메서드 2의 코드에 또 다른 오류가 있습니다.라인

echo add_shortcode('someshortocode', 'someshortocode_callback');

동작할 수 없습니다.add_shortcode()아무것도 반환하지 않습니다.이 코드는 다음과 같습니다.

<?php $post = get_post();

if ( $post && preg_match( '/vc_row/', $post->post_content ) ) {
// Visual composer works on current page/post
    wc_print_notice('VC ON', 'notice');
} else {
    wc_print_notice('VC OFF', 'notice');
    add_shortcode('someshortocode', 'someshortocode_callback');
    echo do_shortcode('[someshortocode]');
}; ?>

언급URL : https://stackoverflow.com/questions/46083958/render-visual-composer-shortcodes-onto-page

반응형