我的一个客户希望在他的 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;
Run Code Online (Sandbox Code Playgroud)
这有效......但不是真的。
项目页面是使用可视化作曲家构建的。并且一些元素具有背景颜色或填充。视觉作曲家为这些元素提供了独特的类,如
.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 { …Run Code Online (Sandbox Code Playgroud)