$this->attributes(), 'render_callback' => [$this, 'render'] ) ); } function attributes(){ return array( 'align' => array( 'type' => 'string', 'default' => 'wide' ), 'cId' => array( 'type' => 'string', 'default' => '' ), 'layout' => array( 'type' => 'string', 'default' => 'grid' ), 'subLayout' => array( 'type' => 'string', 'default' => 'default' ), 'columns' => array( 'type' => 'object', 'default' => array( 'desktop' => 3, 'tablet' => 2, 'mobile' => 1 ) ), 'columnGap' => array( 'type' => 'number', 'default' => 15 ), 'rowGap' => array( 'type' => 'number', 'default' => 15 ), 'isContentEqualHight' => array( 'type' => 'boolean', 'default' => true ), 'postType' => array( 'type' => 'string', 'default' => 'post' ), 'selectedCategories' => array( 'type' => 'array', 'default' => array() ), 'isPostsPerPageAll' => array( 'type' => 'boolean', 'default' => false ), 'postsPerPage' => array( 'type' => 'number', 'default' => 12 ), 'postsOrderBy' => array( 'type' => 'string', 'default' => 'date' ), 'postsOrder' => array( 'type' => 'string', 'default' => 'desc' ), 'contentAlign' => array( 'type' => 'string', 'default' => 'left' ), 'contentBG' => array( 'type' => 'object', 'default' => array( 'color' => '#f4f2fc' ) ), 'contentPadding' => array( 'type' => 'object', 'default' => array( 'vertical' => '20px', 'horizontal' => '25px' ) ), 'border' => array( 'type' => 'object', 'default' => array( 'radius' => '5px' ) ), 'isFImg' => array( 'type' => 'boolean', 'default' => true ), 'isFImgLink' => array( 'type' => 'boolean', 'default' => false ), 'isTitle' => array( 'type' => 'boolean', 'default' => true ), 'isTitleLink' => array( 'type' => 'boolean', 'default' => true ), 'titleTypo' => array( 'type' => 'object', 'default' => array( 'fontFamily' => 'Roboto', 'fontSize' => 25, 'googleFontLink' => 'https://fonts.googleapis.com/css2?family=Roboto&display=swap' ) ), 'titleColor' => array( 'type' => 'string', 'default' => '#4527a4' ), 'titleMargin' => array( 'type' => 'object', 'default' => array( 'bottom' => '15px' ) ), 'isMeta' => array( 'type' => 'boolean', 'default' => true ), 'isMetaAuthor' => array( 'type' => 'boolean', 'default' => true ), 'isMetaDate' => array( 'type' => 'boolean', 'default' => true ), 'isMetaCategory' => array( 'type' => 'boolean', 'default' => true ), 'metaCategoryIn' => array( 'type' => 'string', 'default' => 'content' ), 'isMetaComment' => array( 'type' => 'boolean', 'default' => false ), 'metaTypo' => array( 'type' => 'object', 'default' => array( 'fontSize' => 13, 'textTransform' => 'uppercase' ) ), 'metaTextColor' => array( 'type' => 'string', 'default' => '#333' ), 'metaLinkColor' => array( 'type' => 'string', 'default' => '#8344c5' ), 'metaIconColor' => array( 'type' => 'string', 'default' => '#4527a4' ), 'metaMargin' => array( 'type' => 'object', 'default' => array( 'bottom' => '15px' ) ), 'isExcerpt' => array( 'type' => 'boolean', 'default' => true ), 'excerptLength' => array( 'type' => 'number', 'default' => 25 ), 'excerptAlign' => array( 'type' => 'string', 'default' => 'justify' ), 'excerptTypo' => array( 'type' => 'object', 'default' => array( 'fontSize' => 15 ) ), 'excerptColor' => array( 'type' => 'string', 'default' => '#333' ), 'excerptMargin' => array( 'type' => 'object', 'default' => array( 'bottom' => '10px' ) ), 'isReadMore' => array( 'type' => 'boolean', 'default' => true ), 'readMoreLabel' => array( 'type' => 'string', 'default' => 'Read More' ), 'isLinkNewTab' => array( 'type' => 'boolean', 'default' => false ), 'readMoreAlign' => array( 'type' => 'string', 'default' => 'left' ), 'readMoreTypo' => array( 'type' => 'object', 'default' => array( 'fontSize' => 14, 'textTransform' => 'uppercase', 'fontWeight' => 600 ) ), 'readMoreColors' => array( 'type' => 'object', 'default' => array( 'color' => '#fff', 'bg' => '#8344c5' ) ), 'readMoreHovColors' => array( 'type' => 'object', 'default' => array( 'color' => '#fff', 'bg' => '#4527a4' ) ), 'readMorePadding' => array( 'type' => 'object', 'default' => array( 'vertical' => '12px', 'horizontal' => '35px' ) ), 'readMoreBorder' => array( 'type' => 'object', 'default' => array( 'radius' => '3px' ) ) ); } function render( $attributes ){ extract( $attributes ); // $taxonomies = get_object_taxonomies( $postType, 'array' ); // foreach( $taxonomies as $tax ){ // if( $tax->hierarchical ){ // $terms = get_terms( $tax->name, array( // 'orderby' => 'term_id', // 'order' => 'ASC', // 'hide_empty' => true, // ) ); // } // } // Generate Styles $postsStyles = new BBlocksStyleGenerator(); $postsStyles::addStyle( "#bBlocksPosts-$cId .bBlocksPost", array( 'margin-bottom' => 'masonry' === $layout ? $rowGap.'px' : '0px', $border['styles'] ?? 'border-radius: 5px;' => '' ) ); $postsStyles::addStyle( "#bBlocksPosts-$cId .bBlocksPostDefault, #bBlocksPosts-$cId .bBlocksPostSideImage", array( 'text-align' => $contentAlign, $contentBG['styles'] ?? 'background-color: #f4f2fc;' => '' ) ); $postsStyles::addStyle( "#bBlocksPosts-$cId .bBlocksPost .bBlocksPostText", array( 'padding' => $contentPadding['styles'] ?? '20px 25px' ) ); $postsStyles::addStyle( "#bBlocksPosts-$cId .bBlocksPostOverlay .bBlocksPostText", array( $contentBG['styles'] ?? 'background-color: #f4f2fc;' => '', 'align-items' => 'left' === $contentAlign ? 'flex-start' : ( 'right' === $contentAlign ? 'flex-end' : ( 'center' === $contentAlign ? 'center' : 'stretch' ) ) ) ); $postsStyles::addStyle( "#bBlocksPosts-$cId .bBlocksPost .bBlocksPostTitle", array( 'text-align' => $contentAlign, $titleTypo['styles'] ?? 'font-size: 25px;' => '', 'color' => $titleColor, 'margin' => $titleMargin['styles'] ?? '0 0 15px 0' ) ); $postsStyles::addStyle( "#bBlocksPosts-$cId .bBlocksPost .bBlocksPostTitle a", array( 'color' => $titleColor ) ); $postsStyles::addStyle( "#bBlocksPosts-$cId .bBlocksPost .bBlocksPostMeta", array( 'text-align' => $contentAlign, $metaTypo['styles'] ?? 'font-size: 13px; text-transform: uppercase;' => '', 'color' => $metaTextColor, 'margin' => $metaMargin['styles'] ?? '0 0 15px 0' ) ); $postsStyles::addStyle( "#bBlocksPosts-$cId .bBlocksPost .bBlocksPostMeta a", array( 'color' => $metaLinkColor ) ); $postsStyles::addStyle( "#bBlocksPosts-$cId .bBlocksPost .bBlocksPostMeta .dashicons", array( 'color' => $metaIconColor ) ); $postsStyles::addStyle( "#bBlocksPosts-$cId .bBlocksPost .bBlocksPostFImgCats", array( $metaTypo['styles'] ?? 'font-size: 13px; text-transform: uppercase;' => '' ) ); $postsStyles::addStyle( "#bBlocksPosts-$cId .bBlocksPost .bBlocksPostExcerpt", array( 'text-align' => $excerptAlign, $excerptTypo['styles'] ?? 'font-size: 15px;' => '', 'color' => $excerptColor, 'margin' => $excerptMargin['styles'] ?? '0 0 10px 0' ) ); $postsStyles::addStyle( "#bBlocksPosts-$cId .bBlocksPost .bBlocksPostReadMore", array( 'text-align' => $readMoreAlign ) ); $postsStyles::addStyle( "#bBlocksPosts-$cId .bBlocksPost .bBlocksPostReadMore a", array( $readMoreTypo['styles'] ?? 'font-size: 14px; text-transform: uppercase; font-weight: 600;' => '', $readMoreColors['styles'] ?? 'color: #fff; background: #8344c5;' => '', 'padding' => $readMorePadding['styles'] ?? '12px 35px', $readMoreBorder['styles'] ?? 'border-radius: 3px;' => '' ) ); $postsStyles::addStyle( "#bBlocksPosts-$cId .bBlocksPost .bBlocksPostReadMore a:hover", array( $readMoreHovColors['styles'] ?? 'color: #fff; background: #4527a4;' => '' ) ); $postsStyles::addStyle( "#bBlocksPosts-$cId .bBlocksGridPosts", array( 'grid-gap' => $rowGap .'px '. $columnGap .'px', 'align-items' => false === $isContentEqualHight ? 'start' : 'initial' ) ); $postsStyles::addStyle( "#bBlocksPosts-$cId .bBlocksMasonryPosts", array( 'gap' => $columnGap . 'px' ) ); // All Posts $posts = get_posts( [ 'post_type' => $postType, 'category' => $selectedCategories, 'posts_per_page' => $isPostsPerPageAll ? -1 : $postsPerPage, 'orderby' => $postsOrderBy, 'order' => $postsOrder ] ); ob_start(); ?>
' id='bBlocksPosts-'>
columns-tablet- columns-mobile-'> foreachPosts( $attributes, $posts ); ?>
cols-tablet- cols-mobile-'> foreachPosts( $attributes, $posts ); ?>
defaultLayout( $attributes, $post ); } else if ( 'left-image' === $subLayout || 'right-image' === $subLayout ) { echo $this->sideImgLayout( $attributes, $post ); } else if ( 'overlay-content' === $subLayout || 'overlay-content-hover' === $subLayout || 'overlay-box' === $subLayout ) { echo $this->overlayLayout( $attributes, $post ); } else { ?>

postExcerpt( $attributes, $post ) . $this->postReadMore( $attributes, $post ) : ''; ob_start(); ?>
postFeatureImg( $attributes, $post ); ?>
postTitle( $attributes, $post ) . $this->postMetaData( $attributes, $post ) . $titleMetaFilter; ?>
'> postFeatureImg( $attributes, $post ) : ''; ?>
postTitle( $attributes, $post ) . $this->postMetaData( $attributes, $post ) . $this->postExcerpt( $attributes, $post ) . $this->postReadMore( $attributes, $post ); ?>
postFeatureImg( $attributes, $post ) : ''; ?>
ID ); ob_start(); ?>
'>
postTitle( $attributes, $post ) . $this->postMetaData( $attributes, $post ); ?> postExcerpt( $attributes, $post ) . $this->postReadMore( $attributes, $post ) : ''; ?>
ID ); $tab = $isLinkNewTab ? '_blank' : '_self'; if( $isFImg && $imgUrl ){ ob_start(); ?>
ID ) ) ." target='$tab' rel='noreferrer'>" : ''; ?> ". get_the_category_list( ' ', '', $post->ID ) ."" : ''; ?>

ID ) ) ." target='$tab' rel='noreferrer'>$post->post_title" : $post->post_title; ?>

metaAuthor( $attributes, $post ) . $this->metaDate( $attributes, $post ) . $this->metaCategories( $attributes, $post ) . $this->metaComment( $attributes, $post ); ?>
  ID ); ?>   ID ); ?>   ID ); ?>   ID )->total_comments; ?>
ID ) ), 0, $excerptLength ) ); ?>
true, 'show_in_rest' => true, ), 'objects' ); $options = array(); foreach ( $post_types as $post_type ) { if ( 'product' === $post_type->name ) { continue; } if ( 'attachment' === $post_type->name ) { continue; } if ( 'page' === $post_type->name ) { continue; } $options[] = array( 'value' => $post_type->name, 'label' => $post_type->label ); } return $options; } // Post Types function customRestAPI() { $post_type = $this->post_types(); foreach ( $post_type as $key => $value ) { register_rest_field( $value['value'], 'wbAuthor', array( 'get_callback' => function ( $obj ) { $author['name'] = get_the_author_meta( 'display_name', isset( $obj['author'] ) ? $obj['author'] : '' ); $author['link'] = get_author_posts_url( isset( $obj['author'] ) ? $obj['author'] : '' ); return $author; }, 'schema' => array( 'description' => __( 'Author name and link', 'b-blocks' ), 'type' => 'string', ) ) ); register_rest_field( $value['value'], 'wbDate', array( 'get_callback' => function ( $obj ) { return get_the_date( 'M j, Y', $obj['id'] ); }, 'schema' => array( 'description' => __( 'Author name and link', 'b-blocks' ), 'type' => 'string', ) ) ); register_rest_field( $value['value'], 'wbCategories', array( 'get_callback' => function ( $obj ) { $catsLink['space'] = get_the_category_list( esc_html__( ' ' ), '', $obj['id'] ); $catsLink['coma'] = get_the_category_list( esc_html__( ', ' ), '', $obj['id'] ); return $catsLink; }, 'schema' => array( 'description' => __( 'Category link lists', 'b-blocks' ), 'type' => 'string', ) ) ); register_rest_field( $value['value'], 'wbComment', array( 'get_callback' => function ( $obj ) { return wp_count_comments( $obj['id'] )->total_comments; }, 'schema' => array( 'description' => __( 'Comment', 'b-blocks' ), 'type' => 'number', ) ) ); } } // Custom Rest API } new BBlocksPosts();