如何生成vc_shortcodes-custom-css? Visual Composer

时间:2018-02-19 10:19:38

标签: php wordpress visual-composer

我的客户希望在他的Wordpress网站上有一个“月度项目”功能。但是有一个存档页面。

我的想法是创建一个自定义帖子类型并称之为项目。在这里,客户可以管理项目并创建新项目。

使用这段代码,我可以从最新的项目帖子中获取内容,并将该内容放在主要的“月度项目”页面上,而所有过去的项目都在归档页面上。

$latest_cpt = get_posts("post_type=projects&numberposts=1");
$my_postid = $latest_cpt[0]->ID; //This is page id or post id
$content_post = get_post($my_postid);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;

这有效......但不是真的。

项目页面使用visual composer构建。并且一些元素具有背景颜色或填充。 Visual composer为这些元素提供了独特的类,如

.vc_custom_1516702624245

并在页面加载时添加自定义样式标记。像这样的东西

<style type="text/css" data-type="vc_shortcodes-custom-css">
    .vc_custom_1516711125312 {
        padding-top: 75px !important;
        padding-bottom: 75px !important;
        background-color: #f3f5f6 !important;
    }

    .vc_custom_1516702624245 {
        background-color: #f3f5f6 !important;
    }

    .vc_custom_1516711013808 {
        margin-top: -106px !important;
    }

    .vc_custom_1516702490896 {
        padding-left: 50px !important;
    }

    .vc_custom_1516703325534 {
        margin-top: -15px !important;
    }

    .vc_custom_1516702744160 {
        background-position: center !important;
        background-repeat: no-repeat !important;
        background-size: cover !important;
    }

    .vc_custom_1516702987431 {
        padding-right: 65px !important;
    }

    .vc_custom_1516709810401 {
        border-radius: 3px !important;
    }
</style>

我的方法存在的问题是,视觉作曲家不会为正在加载的帖子内容创建样式标记

因此,很多次要的造型细节都会丢失。

Image: Page content on archive page (how it should look)

Image: Page content on "project of the month" page

TL:DR 视觉作曲家风格未生成post_content

2 个答案:

答案 0 :(得分:3)

您可以使用addShortcodesCustomCss的部分Vc_base功能:

$shortcodes_custom_css = get_post_meta( $id, '_wpb_shortcodes_custom_css', true );
if ( ! empty( $shortcodes_custom_css ) ) {
    $shortcodes_custom_css = strip_tags( $shortcodes_custom_css );
    echo '<style type="text/css" data-type="vc_shortcodes-custom-css">';
    echo $shortcodes_custom_css;
    echo '</style>';
}

$id替换为您$my_postid,如果需要,将echo替换为$content .=

答案 1 :(得分:0)

function usp_modify_post_type($post_type) { 
  return 'post,footer,header,page,product,'; // Edit post type as needed
}

add_filter('usp_post_type', 'usp_modify_post_type');