'render_ap_block_posts', ] ); } add_action( 'init', 'ap_block_posts_init' ); function render_ap_block_posts( $attributes ) { extract( $attributes ); $align ?? $align = 'wide'; $cId ?? $cId = ''; $layout ?? $layout = 'grid'; $subLayout ?? $subLayout = 'default'; $columns ?? $columns = array( 'desktop' => 3, 'tablet' => 2, 'mobile' => 1, ); $columnGap ?? $columnGap = 10; $rowGap ?? $rowGap = 10; $isContentEqualHight ?? $isContentEqualHight = 'true'; $sliderContentHeight ?? $sliderContentHeight = 350; $postType ?? $postType = 'post'; $selectedCategories ?? $selectedCategories = []; $isPostsPerPageAll ?? $isPostsPerPageAll = 'false'; $postsPerPage ?? $postsPerPage = 12; $postsOrderBy ?? $postsOrderBy = 'date'; $postsOrder ?? $postsOrder = 'desc'; $contentAlign ?? $contentAlign = 'left'; $contentBGColor ?? $contentBGColor = '#f4f2fc'; $postTextPTB ?? $postTextPTB = 15; $postTextPLR ?? $postTextPLR = 25; $borderColor ?? $borderColor = '#4527a400'; $sliderIsLoop ?? $sliderIsLoop = true; $sliderIsAutoplay ?? $sliderIsAutoplay = true; $sliderSpeed ?? $sliderSpeed = .5; $sliderIsFade ?? $sliderIsFade = false; $sliderIsTouchMove ?? $sliderIsTouchMove = false; $sliderIsPage ?? $sliderIsPage = true; $sliderIsPageClickable ?? $sliderIsPageClickable = true; $sliderIsPageDynamic ?? $sliderIsPageDynamic = true; $sliderPageColor ?? $sliderPageColor = '#8344c5'; $sliderPageWidth ?? $sliderPageWidth = 15; $sliderPageHeight ?? $sliderPageHeight = 15; $sliderPageRadius ?? $sliderPageRadius = 50; $sliderPageRadiusType ?? $sliderPageRadiusType = '%'; $sliderIsPrevNext ?? $sliderIsPrevNext = true; $sliderPrevNextColor ?? $sliderPrevNextColor = '#4527a4'; $isFImg ?? $isFImg = 'true'; $isFImgLink ?? $isFImgLink = 'false'; $isTitle ?? $isTitle = 'true'; $isTitleLink ?? $isTitleLink = 'true'; $titleFontSize ?? $titleFontSize = 25; $titleColor ?? $titleColor = '#4527a4'; $titleMB ?? $titleMB = 15; $isMeta ?? $isMeta = 'true'; $isMetaAuthor ?? $isMetaAuthor = 'true'; $isMetaDate ?? $isMetaDate = 'true'; $isMetaCategory ?? $isMetaCategory = 'true'; $metaCategoryIn ?? $metaCategoryIn = 'content'; $isMetaComment ?? $isMetaComment = 'false'; $metaFontSize ?? $metaFontSize = 13; $metaTransform ?? $metaTransform = 'uppercase'; $metaTextColor ?? $metaTextColor = '#333'; $metaLinkColor ?? $metaLinkColor = '#8344c5'; $metaIconColor ?? $metaIconColor = '#4527a4'; $metaMB ?? $metaMB = 15; $isExcerpt ?? $isExcerpt = 'true'; $excerptLength ?? $excerptLength = 25; $excerptAlign ?? $excerptAlign = 'justify'; $excerptColor ?? $excerptColor = '#333'; $excerptMB ?? $excerptMB = 15; $isReadMore ?? $isReadMore = 'true'; $readMoreLabel ?? $readMoreLabel = 'Read More'; $isLinkNewTab ?? $isLinkNewTab = 'false'; $readMoreAlign ?? $readMoreAlign = 'left'; $readMoreFontSize ?? $readMoreFontSize = 14; $readMoreTransform ?? $readMoreTransform = 'uppercase'; $readMoreFontWeight ?? $readMoreFontWeight = '600'; $readMoreColor ?? $readMoreColor = '#4527a4'; $readMoreHovColor ?? $readMoreHovColor = '#8344c5'; // All Posts $posts = get_posts( [ 'post_type' => $postType, 'category' => $selectedCategories, 'posts_per_page' => 'true' == $isPostsPerPageAll ? -1 : $postsPerPage, 'orderby' => $postsOrderBy, 'order' => $postsOrder, ] ); $alignClass = '' == $align ? '' : 'align' . $align; ob_start(); echo '
'; if ( 'grid' == $layout ) { $alignItems = 'false' == $isContentEqualHight ? 'start' : 'initial'; echo '
'; foreach ( $posts as $post ) { if ( 'default' == $subLayout || 'title-meta' == $subLayout ) { echo APBlockLDefault( $attributes, $post ); } else if ( 'left-image' == $subLayout || 'right-image' == $subLayout ) { echo APBlockLSideImage( $attributes, $post ); } else if ( 'overlay-content' == $subLayout || 'overlay-content-hover' == $subLayout || 'overlay-box' == $subLayout ) { echo APBlockLOverlay( $attributes, $post ); } else { echo '

Please, select a sub layout

'; } } echo '
'; } else if ( 'masonry' == $layout ) { echo '
'; foreach ( $posts as $post ) { if ( 'default' == $subLayout || 'title-meta' == $subLayout ) { echo APBlockLDefault( $attributes, $post ); } else if ( 'left-image' == $subLayout || 'right-image' == $subLayout ) { echo APBlockLSideImage( $attributes, $post ); } else if ( 'overlay-content' == $subLayout || 'overlay-content-hover' == $subLayout || 'overlay-box' == $subLayout ) { echo APBlockLOverlay( $attributes, $post ); } else { echo '

Please, select a sub layout

'; } } echo '
'; } else if ( 'slider' == $layout ) { $paginationDiv = $sliderIsPage ? '
' : ''; $prevNext = $sliderIsPrevNext ? '
' : ''; echo '
'; foreach ( $posts as $post ) { if ( 'default' == $subLayout || 'title-meta' == $subLayout ) { echo APBlockLDefault( $attributes, $post ); } else if ( 'left-image' == $subLayout || 'right-image' == $subLayout ) { echo APBlockLSideImage( $attributes, $post ); } else if ( 'overlay-content' == $subLayout || 'overlay-content-hover' == $subLayout || 'overlay-box' == $subLayout ) { echo APBlockLOverlay( $attributes, $post ); } else { echo '

Please, select a sub layout

'; } } echo '
' . $paginationDiv . $prevNext . '
'; } else { echo ''; } echo '
'; return ob_get_clean(); } // layout Component // Default function APBlockLDefault( $attributes, $post ) { extract( $attributes ); $layout ?? $layout = 'grid'; $subLayout ?? $subLayout = 'default'; $rowGap ?? $rowGap = 10; $contentAlign ?? $contentAlign = 'left'; $contentBGColor ?? $contentBGColor = '#f4f2fc'; $postTextPTB ?? $postTextPTB = 15; $postTextPLR ?? $postTextPLR = 25; $borderColor ?? $borderColor = '#4527a400'; $articleMB = 'masonry' == $layout ? $rowGap . 'px' : 0; $titleMetaFilter = 'title-meta' != $subLayout ? APBlockSExcerpt( $attributes, $post ) . APBlockSReadMore( $attributes, $post ) : ''; $slideClass = 'slider' == $layout ? ' swiper-slide' : ''; return '
' . APBlockSFeatureImg( $attributes, $post ) . '
' . APBlockSTitle( $attributes, $post ) . APBlockSMetaData( $attributes, $post ) . $titleMetaFilter . '
'; } // Side Image function APBlockLSideImage( $attributes, $post ) { extract( $attributes ); $layout ?? $layout = 'grid'; $subLayout ?? $subLayout = 'default'; $rowGap ?? $rowGap = 10; $contentAlign ?? $contentAlign = 'left'; $contentBGColor ?? $contentBGColor = '#f4f2fc'; $postTextPTB ?? $postTextPTB = 15; $postTextPLR ?? $postTextPLR = 25; $borderColor ?? $borderColor = '#4527a400'; $articleMB = 'masonry' == $layout ? $rowGap . 'px' : 0; $leftImage = 'left-image' == $subLayout ? APBlockSFeatureImg( $attributes, $post ) : ''; $rightImage = 'right-image' == $subLayout ? APBlockSFeatureImg( $attributes, $post ) : ''; $leftImgClass = 'left-image' == $subLayout ? ' leftImage' : ''; $rightImgClass = 'right-image' == $subLayout ? ' rightImage' : ''; $displayCSS = get_the_post_thumbnail_url( $post->ID ) ? 'grid' : 'flex'; $slideClass = 'slider' == $layout ? ' swiper-slide' : ''; return '
' . $leftImage . '
' . APBlockSTitle( $attributes, $post ) . APBlockSMetaData( $attributes, $post ) . APBlockSExcerpt( $attributes, $post ) . APBlockSReadMore( $attributes, $post ) . '
' . $rightImage . '
'; } // Overlay function APBlockLOverlay( $attributes, $post ) { extract( $attributes ); $layout ?? $layout = 'grid'; $subLayout ?? $subLayout = 'default'; $rowGap ?? $rowGap = 10; $isFImg ?? $isFImg = 'true'; $contentAlign ?? $contentAlign = 'left'; $contentBGColor ?? $contentBGColor = '#00000080'; $postTextPTB ?? $postTextPTB = 15; $postTextPLR ?? $postTextPLR = 25; $borderColor ?? $borderColor = '#4527a400'; $articleMB = 'masonry' == $layout ? $rowGap . 'px' : 0; $imgUrl = get_the_post_thumbnail_url( $post->ID ); $bgImg = 'true' === $isFImg && $imgUrl ? $imgUrl : ''; $overlayHoverClass = 'overlay-content-hover' == $subLayout && $imgUrl ? ' bBlocksPostArticleOverlayHover' : ''; $overlayBoxClass = 'overlay-box' == $subLayout ? ' bBlocksPostArticleOverlayBox' : ''; $alignItems = 'left' == $contentAlign ? ( 'right' == $contentAlign ? ( 'centre' == $contentAlign ? 'center' : 'flex-end' ) : 'flex-start' ) : ''; $overlayBoxFilter = 'overlay-box' != $subLayout ? APBlockSExcerpt( $attributes, $post ) . APBlockSReadMore( $attributes, $post ) : ''; $slideClass = 'slider' == $layout ? ' swiper-slide' : ''; return '
' . APBlockSTitle( $attributes, $post ) . APBlockSMetaData( $attributes, $post ) . $overlayBoxFilter . '
'; } // Single Components // Feature Image function APBlockSFeatureImg( $attributes, $post ) { extract( $attributes ); $isFImg ?? $isFImg = 'true'; $isFImgLink ?? $isFImgLink = 'false'; $isMetaCategory ?? $isMetaCategory = 'true'; $metaCategoryIn ?? $metaCategoryIn = 'content'; $metaFontSize ?? $metaFontSize = 13; $metaTransform ?? $metaTransform = 'uppercase'; $isLinkNewTab ?? $isLinkNewTab = 'false'; if ( 'true' == $isFImg ) { $imgUrl = get_the_post_thumbnail_url( $post->ID ); $tab = 'true' == $isLinkNewTab ? '_blank' : '_self'; $link = 'true' == $isFImgLink ? '' : ''; $catsInImg = 'true' === $isMetaCategory && 'image' == $metaCategoryIn ? '
' . get_the_category_list( esc_html__( ' ' ), '', $post->ID ) . '
' : ''; return $imgUrl ? '
' . $link . $catsInImg . '
' : ''; } else { return ''; } } // Title function APBlockSTitle( $attributes, $post ) { extract( $attributes ); $contentAlign ?? $contentAlign = 'left'; $isTitle ?? $isTitle = 'true'; $isTitleLink ?? $isTitleLink = 'true'; $titleFontSize ?? $titleFontSize = 25; $titleColor ?? $titleColor = '#4527a4'; $titleMB ?? $titleMB = 15; $isLinkNewTab ?? $isLinkNewTab = 'false'; if ( 'true' == $isTitle ) { $tab = 'true' == $isLinkNewTab ? '_blank' : '_self'; $title = 'true' == $isTitleLink ? '' . $post->post_title . '' : $post->post_title; return '

' . $title . '

'; } else { return ''; } } // Meta Data function APBlockSMetaData( $attributes, $post ) { extract( $attributes ); $contentAlign ?? $contentAlign = 'left'; $isMeta ?? $isMeta = 'true'; $metaFontSize ?? $metaFontSize = 13; $metaTransform ?? $metaTransform = 'uppercase'; $metaTextColor ?? $metaTextColor = '#333'; $metaMB ?? $metaMB = 15; if ( 'true' == $isMeta ) { return '
' . APBlockSMetaAuthor( $attributes, $post ) . APBlockSMetaDate( $attributes, $post ) . APBlockSMetaCategory( $attributes, $post ) . APBlockSMetaComment( $attributes, $post ) . '
'; } else { return ''; } } function APBlockSMetaAuthor( $attributes, $post ) { extract( $attributes ); $isMetaAuthor ?? $isMetaAuthor = 'true'; $metaLinkColor ?? $metaLinkColor = '#8344c5'; $metaIconColor ?? $metaIconColor = '#4527a4'; if ( 'true' == $isMetaAuthor ) { return '   ' . get_the_author_posts_link( $post->ID ) . ' '; } else { return ''; } } function APBlockSMetaDate( $attributes, $post ) { extract( $attributes ); $isMetaDate ?? $isMetaDate = 'true'; $metaTextColor ?? $metaTextColor = '#333'; $metaIconColor ?? $metaIconColor = '#4527a4'; if ( 'true' == $isMetaDate ) { return '   ' . get_the_date( 'M j, Y', $post->ID ) . ' '; } else { return ''; } } function APBlockSMetaCategory( $attributes, $post ) { extract( $attributes ); $isMetaCategory ?? $isMetaCategory = 'true'; $metaCategoryIn ?? $metaCategoryIn = 'content'; $metaLinkColor ?? $metaLinkColor = '#8344c5'; $metaIconColor ?? $metaIconColor = '#4527a4'; if ( 'true' == $isMetaCategory && 'content' == $metaCategoryIn ) { return '   ' . get_the_category_list( esc_html__( ', ' ), '', $post->ID ) . ' '; } else { return ''; } } function APBlockSMetaComment( $attributes, $post ) { extract( $attributes ); $isMetaComment ?? $isMetaComment = 'false'; $metaLinkColor ?? $metaLinkColor = '#8344c5'; $metaIconColor ?? $metaIconColor = '#4527a4'; if ( 'true' == $isMetaComment ) { $comment_count = get_comments( array( 'post_id' => $post->ID, 'count' => true ) ); return '   ' . wp_count_comments( $post->ID )->total_comments . ' '; } else { return ''; } } // Excerpt function APBlockSExcerpt( $attributes, $post ) { extract( $attributes ); $isExcerpt ?? $isExcerpt = 'true'; $excerptLength ?? $excerptLength = 25; $excerptAlign ?? $excerptAlign = 'justify'; $excerptColor ?? $excerptColor = '#333'; $excerptMB ?? $excerptMB = 15; if ( 'true' == $isExcerpt ) { return '
' . implode( ' ', array_slice( explode( ' ', get_post_field( 'post_content', $post->ID ) ), 0, $excerptLength ) ) . '
'; } else { return ''; } } // Read More function APBlockSReadMore( $attributes, $post ) { extract( $attributes ); $isReadMore ?? $isReadMore = 'true'; $readMoreLabel ?? $readMoreLabel = 'Read More'; $isLinkNewTab ?? $isLinkNewTab = 'false'; $readMoreAlign ?? $readMoreAlign = 'left'; $readMoreFontSize ?? $readMoreFontSize = 14; $readMoreTransform ?? $readMoreTransform = 'uppercase'; $readMoreFontWeight ?? $readMoreFontWeight = '600'; $readMoreColor ?? $readMoreColor = '#4527a4'; $readMoreHovColor ?? $readMoreHovColor = '#8344c5'; if ( 'true' == $isReadMore ) { $tab = 'true' == $isLinkNewTab ? '_blank' : '_self'; return '
' . $readMoreLabel . '
'; } else { return ''; } }