'render_b_blocks_posts', ] ); } add_action( 'init', 'b_blocks_posts_init' ); function render_b_blocks_posts( $attributes ) { extract( $attributes ); $align ?? $align = 'full'; $selectedCategories ?? $selectedCategories = []; $postsPerPageAll ?? $postsPerPageAll = 'false'; $postsPerPage ?? $postsPerPage = 12; $postsOrderBy ?? $postsOrderBy = 'date'; $postsOrder ?? $postsOrder = 'desc'; $layout ?? $layout = 'grid'; $columns ?? $columns = 3; $columnGap ?? $columnGap = 10; $rowGap ?? $rowGap = 10; $contentEqualHight ?? $contentEqualHight = 'true'; $contentAlign ?? $contentAlign = 'left'; $contentBGColor ?? $contentBGColor = '#fff'; $postTextPTB ?? $postTextPTB = 15; $postTextPLR ?? $postTextPLR = 15; $shadow ?? $shadow = 'shadow'; $featureImgShow ?? $featureImgShow = 'true'; $titleShow ?? $titleShow = 'true'; $titleFontSize ?? $titleFontSize = 20; $titleColor ?? $titleColor = '#4527a4'; $titleMB ?? $titleMB = 15; $metaShow ?? $metaShow = 'true'; $metaAuthorShow ?? $metaAuthorShow = 'true'; $metaDateShow ?? $metaDateShow = 'true'; $metaCategoryShow ?? $metaCategoryShow = 'true'; $metaCommentShow ?? $metaCommentShow = 'false'; $metaFontSize ?? $metaFontSize = 13; $metaTransform ?? $metaTransform = 'uppercase'; $metaTextColor ?? $metaTextColor = '#333'; $metaLinkColor ?? $metaLinkColor = '#8344c5'; $metaIconColor ?? $metaIconColor = '#4527a4'; $metaMB ?? $metaMB = 15; $excerptShow ?? $excerptShow = 'true'; $excerptLength ?? $excerptLength = 45; $excerptAlign ?? $excerptAlign = 'justify'; $excerptFontSize ?? $excerptFontSize = 15; $excerptColor ?? $excerptColor = '#333'; $excerptMB ?? $excerptMB = 15; $readMoreShow ?? $readMoreShow = 'true'; $readMoreLabel ?? $readMoreLabel = 'Read More'; $readMoreAlign ?? $readMoreAlign = 'left'; $readMoreFontSize ?? $readMoreFontSize = 14; $readMoreTransform ?? $readMoreTransform = 'uppercase'; $readMoreFontWeight ?? $readMoreFontWeight = '600'; $readMoreColor ?? $readMoreColor = '#4527a4'; $readMoreHovColor ?? $readMoreHovColor = '#8344c5'; // All Posts $posts = get_posts( [ 'category' => $selectedCategories, 'posts_per_page' => 'true' == $postsPerPageAll ? -1 : $postsPerPage, 'orderby' => $postsOrderBy, 'order' => $postsOrder, ] ); $alignClass = '' == $align ? '' : 'align' . $align; ob_start(); echo '
'; if ( 'grid' == $layout ) { echo '
'; foreach ( $posts as $post ) { $contentHeight = 'true' == $contentEqualHight ? "100%" : "auto"; echo '
' . bBlocksPostFeatureImg( $featureImgShow, $post ) . '
' . bBlocksPostTitle( $titleShow, $post, $contentAlign, $titleFontSize, $titleColor, $titleMB ) . bBlocksPostMetaData( $metaShow, $post, $metaAuthorShow, $metaDateShow, $metaCategoryShow, $metaCommentShow, $contentAlign, $metaFontSize, $metaTransform, $metaTextColor, $metaLinkColor, $metaIconColor, $metaMB ) . bBlocksPostExcerpt( $excerptShow, $post, $excerptAlign, $excerptFontSize, $excerptColor, $excerptMB, $excerptLength ) . bBlocksPostReadMore( $readMoreShow, $post, $readMoreAlign, $readMoreFontSize, $readMoreTransform, $readMoreFontWeight, $readMoreColor, $readMoreHovColor, $readMoreLabel ) . '
'; } echo '
'; } else if ( 'masonry' == $layout ) { echo '
'; foreach ( $posts as $post ) { echo '
' . bBlocksPostFeatureImg( $featureImgShow, $post ) . '
' . bBlocksPostTitle( $titleShow, $post, $contentAlign, $titleFontSize, $titleColor, $titleMB ) . bBlocksPostMetaData( $metaShow, $post, $metaAuthorShow, $metaDateShow, $metaCategoryShow, $metaCommentShow, $contentAlign, $metaFontSize, $metaTransform, $metaTextColor, $metaLinkColor, $metaIconColor, $metaMB ) . bBlocksPostExcerpt( $excerptShow, $post, $excerptAlign, $excerptFontSize, $excerptColor, $excerptMB, $excerptLength ) . bBlocksPostReadMore( $readMoreShow, $post, $readMoreAlign, $readMoreFontSize, $readMoreTransform, $readMoreFontWeight, $readMoreColor, $readMoreHovColor, $readMoreLabel ) . '
'; } echo '
'; } else { echo ''; } echo '
'; return ob_get_clean(); } // Components // Feature Image function bBlocksPostFeatureImg( $show, $post ) { if ( 'true' == $show ) { return '
' . get_the_post_thumbnail( $post->ID ) . '
'; } else { return ''; } } // Title function bBlocksPostTitle( $show, $post, $align, $fontSize, $color, $mb ) { if ( 'true' == $show ) { return '

' . $post->post_title . '

'; } else { return ''; } } // Meta Data function bBlocksPostMetaData( $show, $post, $authorShow, $dateShow, $categoryShow, $commentShow, $align, $fontSize, $transform, $textColor, $linkColor, $iconColor, $mb ) { if ( 'true' == $show ) { return '

' . bBlocksPostMetaAuthor( $authorShow, $post, $iconColor, $linkColor ) . bBlocksPostMetaDate( $dateShow, $post, $iconColor, $textColor ) . bBlocksPostMetaCategory( $categoryShow, $post, $iconColor, $linkColor ) . bBlocksPostMetaComment( $commentShow, $post, $iconColor, $linkColor ) . '

'; } else { return ''; } } function bBlocksPostMetaAuthor( $show, $post, $iconColor, $linkColor ) { if ( 'true' == $show ) { return '   ' . get_the_author_posts_link( $post->ID ) . ' '; } else { return ''; } } function bBlocksPostMetaDate( $show, $post, $iconColor, $textColor ) { if ( 'true' == $show ) { return '   ' . get_the_date( 'M j, Y', $post->ID ) . ' '; } else { return ''; } } function bBlocksPostMetaCategory( $show, $post, $iconColor, $linkColor ) { if ( 'true' == $show ) { return '   ' . get_the_category_list( ', ', '', $post->ID ) . ' '; } else { return ''; } } function bBlocksPostMetaComment( $show, $post, $iconColor, $linkColor ) { if ( 'true' == $show ) { $comment_count = get_comments( array( 'post_id' => $post->ID, 'count' => true ) ); $view_comment = ''; switch ( $comment_count ) { case "0": $view_comment = esc_html__( 'No Comments', 'b-blocks' ); break; case "1": $view_comment = esc_html__( '1 Comment', 'b-blocks' ); break; default: $view_comment = esc_html__( "$comment_count Comments", 'b-blocks' ); } return '   ' . $view_comment . ' '; } else { return ''; } } // Excerpt function bBlocksPostExcerpt( $show, $post, $align, $fontSize, $color, $mb, $length ) { if ( 'true' == $show ) { return '
' . implode( ' ', array_slice( explode( ' ', get_post_field( 'post_content', $post->ID ) ), 0, $length ) ) . '
'; } else { return ''; } } // Read More function bBlocksPostReadMore( $show, $post, $align, $fontSize, $transform, $fontWeight, $color, $hovColor, $label ) { if ( 'true' == $show ) { return '
' . $label . '
'; } else { return ''; } }