我在 WordPress 中使用 Visual Composer,我想制作一个自定义的 Post Grid。但是 post grid 提供的默认元素是不够的。我想显示帖子的作者、评论数、类别以及标签。我不太熟悉 Visual Composer,但我需要一个正确的方向来获取这些数据?我能做什么?我搜索了他们的文档,但没有找到。如果我需要移动 php 代码,我想知道我移动的是正确的东西。有任何想法吗?如果您需要更多信息,请询问 :D
在此先感谢您的帮助。
最佳答案
如果有人仍在寻找如何在帖子网格中获取 ID 或为网格创建特定小部件的方法,您可以使用我创建的以下代码片段在帖子标题前添加图标。您将在第一个函数中看到您可以调用 $post-ID
以用于任何查询。
//** Case Study Title Block Shortcodes ***********
//********************************
add_filter( 'vc_gitem_template_attribute_case_study_title','vc_gitem_template_attribute_case_study_title', 10, 2 );
function vc_gitem_template_attribute_case_study_title( $value, $data ) {
extract( array_merge( array(
'post' => null,
'data' => '',
), $data ) );
$atts_extended = array();
parse_str( $data, $atts_extended );
$atts = $atts_extended['atts'];
// write all your widget code in here using queries etc
$title = get_the_title($post->ID);
$link = get_permalink($post->ID);
$terms = get_the_terms($post->ID, 'case_categories');
$output = "<h4 class=\"case-title\"><a href=\"". $link ."\">". get_the_icon($terms[0]->term_id) . $title ."</a></h4>";
return $output;
}
add_filter( 'vc_grid_item_shortcodes', 'case_study_title_shortcodes' );
function case_study_title_shortcodes( $shortcodes ) {
$shortcodes['vc_case_study_title'] = array(
'name' => __( 'Case Study Title', 'sage' ),
'base' => 'vc_case_study_title',
'icon' => get_template_directory_uri() . '/assets/images/icon.svg',
'category' => __( 'Content', 'sage' ),
'description' => __( 'Displays the case study title with correct icon', 'sage' ),
'post_type' => Vc_Grid_Item_Editor::postType()
);
return $shortcodes;
}
add_shortcode( 'vc_case_study_title', 'vc_case_study_title_render' );
function vc_case_study_title_render($atts){
$atts = vc_map_get_attributes( 'vc_case_study_title', $atts );
return '{{ case_study_title }}';
}
关于php - WordPress 获取 Visual Composer 的 Post Grid 的 post 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31196353/