WordPress获取Visual Composer的Post Grid的发布数据 [英] WordPress Getting post data for Post Grid of Visual Composer

查看:97
本文介绍了WordPress获取Visual Composer的Post Grid的发布数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在WordPress中使用Visual Composer,我想制作一个自定义的Post Grid.但是,后网格提供的默认元素还不够.我想显示该帖子的作者,其评论数,其类别以及其标签.我对Visual Composer并不是很熟悉,但是我需要一个正确的方向来获取这些数据吗?我能做些什么?我已经搜索了他们的文件,但是没有运气.如果我需要四处移动php代码,我想知道我四处移动是正确的事情.有任何想法吗?如果您需要更多信息,请询问:D

I'm using Visual Composer in WordPress and I want to make a custom Post Grid. But the default elements that the post grid supplies are not enough. I want to show the author of the post, the number of comments it has, the category it has and the Tags it has as well. I'm not really familiar with Visual Composer, but I need a point in the right direction for me to get this data? What can I do? I've search their documents but with no luck. If I need to move around the php code I would like to know what I'm moving around is the right thing. Any ideas? If you need any more information please do ask :D

预先感谢您的帮助.

推荐答案

如果仍然有人在寻找如何在帖子网格中获取ID或为网格创建特定的小部件,则可以使用以下代码段I为在帖子标题之前添加图标而创建.您会在第一个函数中看到可以调用$post-ID以便在任何查询中使用的功能.

If anybody is still looking to find out how to to get the id in a post grid or create a specific widget for the grid you can use the following snippet I creatd for adding an icon before the post title. You will see inside the first function you can call $post-ID for use on any query.

//** 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 }}';
}

这篇关于WordPress获取Visual Composer的Post Grid的发布数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆