Initial commit: Atomaste website

This commit is contained in:
2025-12-10 12:17:30 -05:00
commit 0b9e5d1605
19260 changed files with 5206382 additions and 0 deletions

View File

@@ -0,0 +1,293 @@
<?php
/**
* Related Posts Loader for Astra theme.
*
* @package Astra
* @link https://www.brainstormforce.com
* @since Astra 3.5.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Customizer Initialization
*
* @since 3.5.0
*/
class Astra_Related_Posts_Loader {
/**
* Constructor
*
* @since 3.5.0
*/
public function __construct() {
add_filter( 'astra_theme_defaults', array( $this, 'theme_defaults' ) );
add_action( 'customize_register', array( $this, 'related_posts_customize_register' ), 2 );
// Load Google fonts.
add_action( 'astra_get_fonts', array( $this, 'add_fonts' ), 1 );
}
/**
* Enqueue google fonts.
*
* @return void
*/
public function add_fonts() {
if ( astra_target_rules_for_related_posts() ) {
// Related Posts Section title.
$section_title_font_family = astra_get_option( 'related-posts-section-title-font-family' );
$section_title_font_weight = astra_get_option( 'related-posts-section-title-font-weight' );
Astra_Fonts::add_font( $section_title_font_family, $section_title_font_weight );
// Related Posts - Posts title.
$post_title_font_family = astra_get_option( 'related-posts-title-font-family' );
$post_title_font_weight = astra_get_option( 'related-posts-title-font-weight' );
Astra_Fonts::add_font( $post_title_font_family, $post_title_font_weight );
// Related Posts - Meta Font.
$meta_font_family = astra_get_option( 'related-posts-meta-font-family' );
$meta_font_weight = astra_get_option( 'related-posts-meta-font-weight' );
Astra_Fonts::add_font( $meta_font_family, $meta_font_weight );
// Related Posts - Content Font.
$content_font_family = astra_get_option( 'related-posts-content-font-family' );
$content_font_weight = astra_get_option( 'related-posts-content-font-weight' );
Astra_Fonts::add_font( $content_font_family, $content_font_weight );
}
}
/**
* Set Options Default Values
*
* @param array $defaults Astra options default value array.
* @return array
*/
public function theme_defaults( $defaults ) {
/**
* Update Astra default color and typography values. To not update directly on existing users site, added backwards.
*
* @since 4.0.0
*/
$apply_new_default_color_typo_values = Astra_Dynamic_CSS::astra_check_default_color_typo();
$astra_options = Astra_Theme_Options::get_astra_options();
$astra_blog_update = Astra_Dynamic_CSS::astra_4_6_0_compatibility();
// Related Posts.
$defaults['enable-related-posts'] = false;
$defaults['related-posts-title'] = __( 'Related Posts', 'astra' );
$defaults['releted-posts-title-alignment'] = 'left';
$defaults['related-posts-total-count'] = 2;
$defaults['enable-related-posts-excerpt'] = false;
$defaults['related-posts-box-placement'] = 'default';
$defaults['related-posts-outside-location'] = 'above';
$defaults['related-posts-container-width'] = $astra_blog_update ? '' : 'fallback';
$defaults['related-posts-excerpt-count'] = 25;
$defaults['related-posts-based-on'] = 'categories';
$defaults['related-posts-order-by'] = 'date';
$defaults['related-posts-order'] = 'asc';
$defaults['related-posts-grid-responsive'] = array(
'desktop' => '2-equal',
'tablet' => '2-equal',
'mobile' => 'full',
);
$defaults['related-posts-structure'] = array(
'featured-image',
'title-meta',
);
$defaults['related-posts-tag-style'] = 'none';
$defaults['related-posts-category-style'] = 'none';
$defaults['related-posts-date-format'] = '';
$defaults['related-posts-meta-date-type'] = 'published';
$defaults['related-posts-author-avatar-size'] = '';
$defaults['related-posts-author-avatar'] = false;
$defaults['related-posts-author-prefix-label'] = astra_default_strings( 'string-blog-meta-author-by', false );
$defaults['related-posts-image-size'] = '';
$defaults['related-posts-image-custom-scale-width'] = 16;
$defaults['related-posts-image-custom-scale-height'] = 9;
$defaults['related-posts-image-ratio-pre-scale'] = '16/9';
$defaults['related-posts-image-ratio-type'] = '';
$defaults['related-posts-meta-structure'] = array(
'comments',
'category',
'author',
);
// Related Posts - Color styles.
$defaults['related-posts-text-color'] = $apply_new_default_color_typo_values ? 'var(--ast-global-color-2)' : '';
$defaults['related-posts-link-color'] = '';
$defaults['related-posts-title-color'] = $apply_new_default_color_typo_values ? 'var(--ast-global-color-2)' : '';
$defaults['related-posts-background-color'] = '';
$defaults['related-posts-meta-color'] = '';
$defaults['related-posts-link-hover-color'] = '';
$defaults['related-posts-meta-link-hover-color'] = '';
// Related Posts - Title typo.
$defaults['related-posts-section-title-font-family'] = 'inherit';
$defaults['related-posts-section-title-font-weight'] = 'inherit';
$defaults['related-posts-section-title-text-transform'] = '';
$defaults['related-posts-section-title-line-height'] = $apply_new_default_color_typo_values ? '1.25' : '';
$defaults['related-posts-section-title-font-extras'] = array(
'line-height' => ! isset( $astra_options['related-posts-section-title-font-extras'] ) && isset( $astra_options['related-posts-section-title-line-height'] ) ? $astra_options['related-posts-section-title-line-height'] : '1.6',
'line-height-unit' => 'em',
'letter-spacing' => '',
'letter-spacing-unit' => 'px',
'text-transform' => ! isset( $astra_options['related-posts-section-title-font-extras'] ) && isset( $astra_options['related-posts-section-title-text-transform'] ) ? $astra_options['related-posts-section-title-text-transform'] : '',
'text-decoration' => '',
);
$defaults['related-posts-section-title-font-size'] = array(
'desktop' => $apply_new_default_color_typo_values ? '26' : '30',
'tablet' => '',
'mobile' => '',
'desktop-unit' => 'px',
'tablet-unit' => 'px',
'mobile-unit' => 'px',
);
// Related Posts - Title typo.
$defaults['related-posts-title-font-family'] = 'inherit';
$defaults['related-posts-title-font-weight'] = $apply_new_default_color_typo_values ? '500' : 'inherit';
$defaults['related-posts-title-text-transform'] = '';
$defaults['related-posts-title-line-height'] = '1';
$defaults['related-posts-title-font-size'] = array(
'desktop' => '20',
'tablet' => '',
'mobile' => '',
'desktop-unit' => 'px',
'tablet-unit' => 'px',
'mobile-unit' => 'px',
);
$defaults['related-posts-title-font-extras'] = array(
'line-height' => ! isset( $astra_options['related-posts-title-font-extras'] ) && isset( $astra_options['related-posts-title-line-height'] ) ? $astra_options['related-posts-title-line-height'] : ( $astra_blog_update ? '1.5' : '1' ),
'line-height-unit' => 'em',
'letter-spacing' => '',
'letter-spacing-unit' => 'px',
'text-transform' => ! isset( $astra_options['related-posts-title-font-extras'] ) && isset( $astra_options['related-posts-title-text-transform'] ) ? $astra_options['related-posts-title-text-transform'] : '',
'text-decoration' => '',
);
// Related Posts - Meta typo.
$defaults['related-posts-meta-font-family'] = 'inherit';
$defaults['related-posts-meta-font-weight'] = 'inherit';
$defaults['related-posts-meta-text-transform'] = '';
$defaults['related-posts-meta-line-height'] = '';
$defaults['related-posts-meta-font-size'] = array(
'desktop' => '14',
'tablet' => '',
'mobile' => '',
'desktop-unit' => 'px',
'tablet-unit' => 'px',
'mobile-unit' => 'px',
);
$defaults['related-posts-meta-font-extras'] = array(
'line-height' => ! isset( $astra_options['related-posts-meta-font-extras'] ) && isset( $astra_options['related-posts-meta-line-height'] ) ? $astra_options['related-posts-meta-line-height'] : '1.6',
'line-height-unit' => 'em',
'letter-spacing' => '',
'letter-spacing-unit' => 'px',
'text-transform' => ! isset( $astra_options['related-posts-meta-font-extras'] ) && isset( $astra_options['related-posts-meta-text-transform'] ) ? $astra_options['related-posts-meta-text-transform'] : '',
'text-decoration' => '',
);
// Related Posts - Content typo.
$defaults['related-posts-content-font-family'] = 'inherit';
$defaults['related-posts-content-font-weight'] = 'inherit';
$defaults['related-posts-content-font-extras'] = array(
'line-height' => ! isset( $astra_options['related-posts-content-font-extras'] ) && isset( $astra_options['related-posts-content-line-height'] ) ? $astra_options['related-posts-content-line-height'] : '',
'line-height-unit' => 'em',
'letter-spacing' => '',
'letter-spacing-unit' => 'px',
'text-transform' => ! isset( $astra_options['related-posts-content-font-extras'] ) && isset( $astra_options['related-posts-content-text-transform'] ) ? $astra_options['related-posts-content-text-transform'] : '',
'text-decoration' => '',
);
$defaults['related-posts-content-font-size'] = array(
'desktop' => '',
'tablet' => '',
'mobile' => '',
'desktop-unit' => 'px',
'tablet-unit' => 'px',
'mobile-unit' => 'px',
);
$defaults['ast-sub-section-related-posts-padding'] = array(
'desktop' => array(
'top' => 2.5,
'right' => 2.5,
'bottom' => 2.5,
'left' => 2.5,
),
'tablet' => array(
'top' => '',
'right' => '',
'bottom' => '',
'left' => '',
),
'mobile' => array(
'top' => '',
'right' => '',
'bottom' => '',
'left' => '',
),
'desktop-unit' => 'em',
'tablet-unit' => 'em',
'mobile-unit' => 'em',
);
$defaults['ast-sub-section-related-posts-margin'] = array(
'desktop' => array(
'top' => 2,
'right' => '',
'bottom' => '',
'left' => '',
),
'tablet' => array(
'top' => '',
'right' => '',
'bottom' => '',
'left' => '',
),
'mobile' => array(
'top' => '',
'right' => '',
'bottom' => '',
'left' => '',
),
'desktop-unit' => 'em',
'tablet-unit' => 'em',
'mobile-unit' => 'em',
);
return $defaults;
}
/**
* Add postMessage support for site title and description for the Theme Customizer.
*
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
*
* @since 3.5.0
*/
public function related_posts_customize_register( $wp_customize ) {
/**
* Register Config control in Related Posts.
*/
// @codingStandardsIgnoreStart WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound
require_once ASTRA_RELATED_POSTS_DIR . 'customizer/class-astra-related-posts-configs.php';
// @codingStandardsIgnoreEnd WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound
}
/**
* Render the Related Posts title for the selective refresh partial.
*
* @since 3.5.0
*/
public function render_related_posts_title() {
return astra_get_option( 'related-posts-title' );
}
}
/**
* Kicking this off by creating NEW instace.
*/
new Astra_Related_Posts_Loader();

View File

@@ -0,0 +1,435 @@
<?php
/**
* Related Posts for Astra theme.
*
* @package Astra
* @link https://www.brainstormforce.com
* @since Astra 3.5.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Breadcrumbs Markup Initial Setup
*
* @since 3.5.0
*/
class Astra_Related_Posts_Markup {
/**
* Constructor
*/
public function __construct() {
add_action( 'astra_content_before', array( $this, 'initialize_related_posts' ) );
}
/**
* Initialize related posts module in Astra.
*
* @since 4.6.0
*/
public function initialize_related_posts() {
$priority = 10;
$location = astra_get_option( 'related-posts-outside-location' );
$module_placement = astra_get_option( 'related-posts-box-placement' );
if ( 'outside' === $module_placement ) {
$action = 'astra_content_after';
if ( astra_get_option( 'enable-comments-area', true ) && 'outside' === astra_get_option( 'comments-box-placement' ) ) {
$priority = 'below' === $location ? 20 : 9;
}
} elseif ( 'inside' === $module_placement ) {
$action = 'astra_entry_bottom';
$priority = 'below' === $location ? 20 : 10;
} else {
$action = 'astra_entry_after';
}
add_action( $action, array( $this, 'astra_related_posts_markup' ), $priority );
}
/**
* Enable/Disable Single Post -> Related Posts section.
*
* @since 3.5.0
* @return void
*/
public function astra_related_posts_markup() {
if ( astra_target_rules_for_related_posts() ) {
$this->astra_get_related_posts();
}
}
/**
* Related Posts markup.
*
* @since 3.5.0
* @return bool
*/
public function astra_get_related_posts() {
global $post;
$post_id = $post->ID;
$related_posts_title = astra_get_i18n_option( 'related-posts-title', _x( '%astra%', 'Single Blog/Post Related Posts: Title', 'astra' ) );
$related_post_meta = astra_get_option( 'related-posts-meta-structure' );
$related_post_structure = astra_get_option_meta( 'related-posts-structure' );
$exclude_ids = apply_filters( 'astra_related_posts_exclude_post_ids', array( $post_id ), $post_id );
$related_posts_total_count = absint( astra_get_option( 'related-posts-total-count', 2 ) );
$module_container_width = astra_get_option( 'related-posts-container-width' );
$module_container_width = 'inside' === astra_get_option( 'related-posts-box-placement' ) ? '' : 'ast-container--' . $module_container_width;
$related_category_style = astra_get_option( 'related-posts-category-style' );
$related_tag_style = astra_get_option( 'related-posts-tag-style' );
// Get related posts by WP_Query.
$query_posts = $this->astra_get_related_posts_by_query( $post_id );
if ( $query_posts ) {
if ( ! $query_posts->have_posts() ) {
return apply_filters( 'astra_related_posts_no_posts_avilable_message', '', $post_id );
}
// Added flag to load wrapper section 'ast-single-related-posts-container' only once, because as we removed 'posts__not_in' param from WP_Query and we conditionally handle posts__not_in below so it needs to verify if there are other posts as well to load, then only we will display wrapper.
$related_posts_section_loaded = false;
do_action( 'astra_related_posts_loop_before' );
/**
* WP_Query posts loop.
*
* Used $post_counter & ( $post_counter < $total_posts_count ) condition to manage posts in while loop because there is case where manual 'post__not_in' condition handling scenario fails within loop.
*
* # CASE EXAMPLE - If total posts set to 4 (where 'post__not_in' not used in WP_Query) so there is a chance that out of those 4 posts, 1 post will be currently active on frontend.
*
* So what will happen in this case - Within following loop the current post will exclude by if condition & only 3 posts will be shown up.
*
* To avoid such cases $post_counter & ( $post_counter < $total_posts_count ) condition used.
*
* @since 3.5.0
*/
$post_counter = 1;
$total_posts_count = $related_posts_total_count + 1;
while ( $query_posts->have_posts() && $post_counter < $total_posts_count ) {
$query_posts->the_post();
$post_id = get_the_ID();
$separator = astra_get_option( 'related-metadata-separator', '/' );
$output_str = astra_get_post_meta( $related_post_meta, $separator, 'related-posts' );
if ( is_array( $exclude_ids ) && ! in_array( $post_id, $exclude_ids ) ) {
if ( false === $related_posts_section_loaded ) {
if ( is_customize_preview() ) {
echo '<div class="customizer-item-block-preview customizer-navigate-on-focus ast-single-related-posts-container ' . esc_attr( $module_container_width ) . '" data-section="ast-sub-section-related-posts" data-type="section">'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
Astra_Builder_UI_Controller::render_customizer_edit_button( 'row-editor-shortcut' );
} else {
echo '<div class="ast-single-related-posts-container ' . esc_attr( $module_container_width ) . '">'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
do_action( 'astra_related_posts_title_before' );
if ( '' !== $related_posts_title ) {
echo apply_filters( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
'astra_related_posts_title',
sprintf(
'<div class="ast-related-posts-title-section"> <%1$s class="ast-related-posts-title"> %2$s </%1$s> </div>',
apply_filters( 'astra_related_posts_box_heading_tag', 'h2' ),
$related_posts_title
)
);
}
do_action( 'astra_related_posts_title_after' );
echo '<div class="ast-related-posts-wrapper">'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
$related_posts_section_loaded = true;
}
?>
<article <?php post_class( 'ast-related-post' ); ?>>
<div class="ast-related-posts-inner-section">
<div class="ast-related-post-content">
<?php
// Render post based on order of Featured Image & Title-Meta.
if ( is_array( $related_post_structure ) ) {
foreach ( $related_post_structure as $post_thumb_title_order ) {
if ( 'featured-image' === $post_thumb_title_order ) {
do_action( 'astra_related_post_before_featured_image', $post_id );
$this->astra_get_related_post_featured_image( $post_id );
do_action( 'astra_related_post_after_featured_image', $post_id );
} else {
?>
<header class="entry-header related-entry-header">
<?php
$this->astra_get_related_post_title( $post_id );
echo apply_filters( 'astra_related_posts_meta_html', '<div class="entry-meta ast-related-cat-style--' . $related_category_style . ' ast-related-tag-style--' . $related_tag_style . '">' . $output_str . '</div>' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
?>
</header>
<?php
}
}
}
?>
<div class="entry-content clear">
<?php
$this->astra_get_related_post_excerpt( $post_id );
$this->astra_get_related_post_read_more( $post_id );
?>
</div>
</div>
</div>
</article>
<?php
$post_counter++;
}
wp_reset_postdata();
}
if ( true === $related_posts_section_loaded ) {
echo '</div> </div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
do_action( 'astra_related_posts_loop_after' );
}
}
/**
* Render Post CTA button HTML marup.
*
* @param int $current_post_id current post ID.
*
* @since 3.5.0
*/
public function astra_get_related_post_read_more( $current_post_id ) {
if ( ! astra_get_option( 'enable-related-posts-excerpt' ) ) {
return;
}
$related_posts_content_type = apply_filters( 'astra_related_posts_content_type', 'excerpt' );
if ( 'full-content' === $related_posts_content_type ) {
return;
}
$target = apply_filters( 'astra_related_post_cta_target', '_self' );
$cta_text = apply_filters( 'astra_related_post_read_more_text', astra_get_i18n_option( 'blog-read-more-text', _x( '%astra%', 'Blogs: Read More Text', 'astra' ) ) );
$blog_read_more_as_button = astra_get_option( 'blog-read-more-as-button' );
$show_read_more_as_button = apply_filters( 'astra_related_post_read_more_as_button', $blog_read_more_as_button );
$class = '';
if ( $show_read_more_as_button ) {
$class = 'ast-button';
}
$custom_class = apply_filters( 'astra_related_post_cta_custom_classes', $class );
do_action( 'astra_related_post_before_cta', $current_post_id );
?>
<p class="ast-related-post-cta read-more">
<a class="ast-related-post-link <?php echo esc_attr( $custom_class ); ?>" href="<?php echo esc_url( apply_filters( 'astra_related_post_link', get_the_permalink(), $current_post_id ) ); ?>" aria-label="<?php echo esc_attr__( 'Related post link', 'astra' ); ?>" target="<?php echo esc_attr( $target ); ?>" rel="bookmark noopener noreferrer"><?php echo esc_html( $cta_text ); ?></a>
</p>
<?php
do_action( 'astra_related_post_after_cta', $current_post_id );
}
/**
* Related Posts Excerpt markup.
*
* @param int $current_post_id current post ID.
*
* @since 3.5.0
*/
public function astra_get_related_post_excerpt( $current_post_id ) {
if ( ! astra_get_option( 'enable-related-posts-excerpt' ) ) {
return;
}
$related_posts_content_type = apply_filters( 'astra_related_posts_content_type', 'excerpt' );
if ( 'full-content' === $related_posts_content_type ) {
return the_content();
}
$excerpt_length = absint( astra_get_option( 'related-posts-excerpt-count' ) );
$excerpt = wp_trim_words( get_the_excerpt(), $excerpt_length );
if ( ! $excerpt ) {
$excerpt = null;
}
$excerpt = apply_filters( 'astra_related_post_excerpt', $excerpt, $current_post_id );
do_action( 'astra_related_post_before_excerpt', $current_post_id );
?>
<p class="ast-related-post-excerpt entry-content clear">
<?php echo wp_kses_post( $excerpt ); ?>
</p>
<?php
do_action( 'astra_related_post_after_excerpt', $current_post_id );
}
/**
* Render Post Title HTML.
*
* @param int $current_post_id current post ID.
*
* @since 3.5.0
*/
public function astra_get_related_post_title( $current_post_id ) {
$related_post_structure = astra_get_option_meta( 'related-posts-structure' );
if ( ! in_array( 'title-meta', $related_post_structure ) ) {
return;
}
$target = apply_filters( 'astra_related_post_title_opening_target', '_self' );
$title_tag = apply_filters( 'astra_related_post_title_tag', 'h3' );
do_action( 'astra_related_post_before_title', $current_post_id );
?>
<<?php echo esc_html( $title_tag ); ?> class="ast-related-post-title entry-title">
<a href="<?php echo esc_url( apply_filters( 'astra_related_post_link', get_the_permalink(), $current_post_id ) ); ?>" target="<?php echo esc_attr( $target ); ?>" rel="bookmark noopener noreferrer"><?php the_title(); ?></a>
</<?php echo esc_html( $title_tag ); ?>>
<?php
do_action( 'astra_related_post_after_title', $current_post_id );
}
/**
* Render Featured Image HTML.
*
* @param int $current_post_id current post ID.
* @param string $before Markup before thumbnail image.
* @param string $after Markup after thumbnail image.
* @param boolean $echo Output print or return.
* @return string|null
*
* @since 3.5.0
*/
public function astra_get_related_post_featured_image( $current_post_id, $before = '', $after = '', $echo = true ) {
$related_post_structure = astra_get_option_meta( 'related-posts-structure' );
if ( ! in_array( 'featured-image', $related_post_structure ) ) {
return;
}
$featured_image_size = astra_get_option( 'related-posts-image-size', 'large' );
$thumbnail_id = get_post_thumbnail_id( $current_post_id );
$alt_text = $thumbnail_id ? get_post_meta( $thumbnail_id, '_wp_attachment_image_alt', true ) : '';
$post_thumb = apply_filters(
'astra_related_post_featured_image_markup',
get_the_post_thumbnail(
$current_post_id,
apply_filters( 'astra_related_posts_thumbnail_default_size', $featured_image_size ),
array(
'alt' => $alt_text ? $alt_text : get_the_title( $current_post_id ),
'itemprop' => apply_filters( 'astra_related_posts_thumbnail_itemprop', '' ),
)
)
);
$appended_class = has_post_thumbnail( $current_post_id ) ? 'post-has-thumb' : 'ast-no-thumb';
$featured_img_markup = '<div class="ast-related-post-featured-section ' . $appended_class . '">';
if ( '' !== $post_thumb ) {
$featured_img_markup .= '<div class="post-thumb-img-content post-thumb">';
$featured_img_markup .= astra_markup_open(
'ast-related-post-image',
array(
'open' => '<a %s>',
'echo' => false,
'attrs' => array(
'class' => '',
'aria-label' => sprintf( __( 'Read more about %s', 'astra' ), esc_attr( get_the_title( $current_post_id ) ) ),
'href' => esc_url( get_permalink() ),
),
)
);
$featured_img_markup .= $post_thumb;
$featured_img_markup .= '</a> </div>';
}
$featured_img_markup = apply_filters( 'astra_related_post_featured_image_after', $featured_img_markup );
$featured_img_markup .= '</div>';
$featured_img_markup = apply_filters( 'astra_related_post_thumbnail', $featured_img_markup, $before, $after );
if ( false === $echo ) {
return $before . $featured_img_markup . $after;
}
echo $before . $featured_img_markup . $after; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
/**
* Get related posts based on configurations.
*
* @param int $post_id Current Post ID.
*
* @since 3.5.0
*
* @return WP_Query|bool
*/
public function astra_get_related_posts_by_query( $post_id ) {
$term_ids = array();
$current_post_type = get_post_type( $post_id );
$related_posts_total_count = absint( astra_get_option( 'related-posts-total-count', 2 ) );
// Taking one post extra in loop because if current post excluded from while loop then this extra one post will cover total post count. Apperently avoided 'post__not_in' from WP_Query.
$updated_total_posts_count = $related_posts_total_count + 1;
$related_posts_order_by = astra_get_option( 'related-posts-order-by', 'date' );
$related_posts_order = astra_get_option( 'related-posts-order', 'desc' );
$related_posts_based_on = astra_get_option( 'related-posts-based-on', 'categories' );
$query_args = array(
'update_post_meta_cache' => false,
'posts_per_page' => $updated_total_posts_count,
'no_found_rows' => true,
'post_status' => 'publish',
'post_type' => $current_post_type,
'orderby' => $related_posts_order_by,
'fields' => 'ids',
'order' => $related_posts_order,
);
if ( 'tags' === $related_posts_based_on ) {
$terms = get_the_tags( $post_id );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
$term_ids = wp_list_pluck( $terms, 'term_id' );
}
$query_args['tag__in'] = $term_ids;
} else {
$terms = get_the_category( $post_id );
/** @psalm-suppress RedundantConditionGivenDocblockType */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
/** @psalm-suppress RedundantConditionGivenDocblockType */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
$term_ids = wp_list_pluck( $terms, 'term_id' );
}
$query_args['category__in'] = $term_ids;
}
$query_args = apply_filters( 'astra_related_posts_query_args', $query_args );
return new WP_Query( $query_args );
}
}
/**
* Kicking this off by creating NEW instance.
*/
new Astra_Related_Posts_Markup();

View File

@@ -0,0 +1,46 @@
<?php
/**
* Related Posts for Astra theme.
*
* @package Astra
* @link https://www.brainstormforce.com
* @since Astra 3.5.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
define( 'ASTRA_RELATED_POSTS_DIR', ASTRA_THEME_DIR . 'inc/modules/related-posts/' );
/**
* Related Posts Initial Setup
*
* @since 3.5.0
*/
class Astra_Related_Posts {
/**
* Constructor function that initializes required actions and hooks
*
* @since 3.5.0
*/
public function __construct() {
// @codingStandardsIgnoreStart WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound
require_once ASTRA_RELATED_POSTS_DIR . 'class-astra-related-posts-loader.php';
require_once ASTRA_RELATED_POSTS_DIR . 'class-astra-related-posts-markup.php';
// @codingStandardsIgnoreEnd WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound
// Include front end files.
if ( ! is_admin() ) {
require_once ASTRA_RELATED_POSTS_DIR . 'css/static-css.php'; // phpcs:ignore: WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound
require_once ASTRA_RELATED_POSTS_DIR . 'css/dynamic-css.php'; // phpcs:ignore: WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound
}
}
}
/**
* Kicking this off by creating NEW instance.
*/
new Astra_Related_Posts();

View File

@@ -0,0 +1,269 @@
<?php
/**
* Related Posts - Dynamic CSS
*
* @package astra
* @since 3.4.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
add_filter( 'astra_dynamic_theme_css', 'astra_related_posts_css', 11 );
/**
* Related Posts - Dynamic CSS
*
* @param string $dynamic_css Astra Dynamic CSS.
* @return String Generated dynamic CSS for Related Posts.
*
* @since 3.4.0
*/
function astra_related_posts_css( $dynamic_css ) {
if ( astra_target_rules_for_related_posts() ) {
$link_color = astra_get_option( 'link-color' );
$related_posts_title_alignment = astra_get_option( 'releted-posts-title-alignment' );
// Added RTL language support for title alignment.
if ( is_rtl() && 'center' !== $related_posts_title_alignment ) {
$related_posts_title_alignment = ( 'left' === $related_posts_title_alignment ) ? 'right' : 'left';
}
// Related Posts Grid layout params.
$related_posts_grid = astra_get_option( 'related-posts-grid-responsive' );
$desktop_grid = ( isset( $related_posts_grid['desktop'] ) ) ? $related_posts_grid['desktop'] : '2-equal';
$tablet_grid = ( isset( $related_posts_grid['tablet'] ) ) ? $related_posts_grid['tablet'] : '2-equal';
$mobile_grid = ( isset( $related_posts_grid['mobile'] ) ) ? $related_posts_grid['mobile'] : 'full';
// Related Posts -> Post Title typography dynamic stylings.
$related_post_title_font_size = astra_get_option( 'related-posts-title-font-size' );
// Related Posts -> Post Meta typography dynamic stylings.
$related_post_meta_font_size = astra_get_option( 'related-posts-meta-font-size' );
// Related Posts -> Content typography dynamic stylings.
$related_post_content_font_size = astra_get_option( 'related-posts-content-font-size' );
// Related Posts -> Section Title typography dynamic stylings.
$related_posts_section_title_font_size = astra_get_option( 'related-posts-section-title-font-size' );
// Setting up container BG color by default to Related Posts's section BG color.
$content_bg_obj = astra_get_option( 'content-bg-obj-responsive' );
$container_bg_color = '#ffffff';
if ( isset( $content_bg_obj['desktop']['background-color'] ) && '' !== $content_bg_obj['desktop']['background-color'] ) {
$container_bg_color = $content_bg_obj['desktop']['background-color'];
}
// Related Posts -> Color dynamic stylings.
$related_posts_title_color = astra_get_option( 'related-posts-title-color' );
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
$related_posts_bg_color = astra_get_option( 'related-posts-background-color', $container_bg_color );
$related_post_text_color = astra_get_option( 'related-posts-text-color' );
$related_posts_meta_color = astra_get_option( 'related-posts-meta-color' );
$related_posts_link_color = astra_get_option( 'related-posts-link-color' );
$related_posts_link_hover_color = astra_get_option( 'related-posts-link-hover-color' );
$related_posts_meta_link_hover_color = astra_get_option( 'related-posts-meta-link-hover-color' );
$author_avatar_size = astra_get_option( 'related-posts-author-avatar-size' );
// Aspect Ratio processing.
$aspect_ratio_type = astra_get_option( 'related-posts-image-ratio-type', '' );
$predefined_scale = astra_get_option( 'related-posts-image-ratio-pre-scale' );
$custom_scale_width = astra_get_option( 'related-posts-image-custom-scale-width', 16 );
$custom_scale_height = astra_get_option( 'related-posts-image-custom-scale-height', 9 );
$aspect_ratio = astra_get_dynamic_image_aspect_ratio( $aspect_ratio_type, $predefined_scale, $custom_scale_width, $custom_scale_height );
$with_aspect_img_width = 'predefined' === $aspect_ratio_type || 'custom' === $aspect_ratio_type ? '100%' : '';
$object_fit = 'custom' === $aspect_ratio_type ? 'cover' : '';
$css_desktop_output = array(
'.ast-single-related-posts-container .ast-related-posts-wrapper' => array(
'grid-template-columns' => Astra_Builder_Helper::$grid_size_mapping[ $desktop_grid ],
),
'.ast-related-posts-inner-section .ast-date-meta .posted-on, .ast-related-posts-inner-section .ast-date-meta .posted-on *' => array(
'background' => esc_attr( $link_color ),
'color' => astra_get_foreground_color( $link_color ),
),
'.ast-related-posts-inner-section .ast-date-meta .posted-on .date-month, .ast-related-posts-inner-section .ast-date-meta .posted-on .date-year' => array(
'color' => astra_get_foreground_color( $link_color ),
),
'.ast-single-related-posts-container' => array(
'background-color' => esc_attr( $related_posts_bg_color ),
),
/**
* Related Posts - Section Title
*/
'.ast-related-posts-title' => astra_get_font_array_css( astra_get_option( 'related-posts-section-title-font-family' ), astra_get_option( 'related-posts-section-title-font-weight' ), $related_posts_section_title_font_size, 'related-posts-section-title-font-extras', $related_posts_title_color ),
'.ast-related-posts-title-section .ast-related-posts-title' => array(
'text-align' => esc_attr( $related_posts_title_alignment ),
),
/**
* Related Posts - Post Title
*/
'.ast-related-post-content .entry-header .ast-related-post-title, .ast-related-post-content .entry-header .ast-related-post-title a' => astra_get_font_array_css( astra_get_option( 'related-posts-title-font-family' ), astra_get_option( 'related-posts-title-font-weight' ), $related_post_title_font_size, 'related-posts-title-font-extras', $related_post_text_color ),
/**
* Related Posts - Meta
*/
'.ast-related-post-content .entry-meta, .ast-related-post-content .entry-meta *' => astra_get_font_array_css( astra_get_option( 'related-posts-meta-font-family' ), astra_get_option( 'related-posts-meta-font-weight' ), $related_post_meta_font_size, 'related-posts-meta-font-extras', $related_posts_meta_color ),
'.ast-related-post-content .entry-meta a:hover, .ast-related-post-content .entry-meta span a span:hover' => array(
'color' => esc_attr( $related_posts_meta_link_hover_color ),
),
/**
* Related Posts - CTA
*/
'.ast-related-post-cta a' => array(
'color' => esc_attr( $related_posts_link_color ),
),
'.ast-related-post-cta a:hover' => array(
'color' => esc_attr( $related_posts_link_hover_color ),
),
/**
* Related Posts - Content
*/
'.ast-related-post-excerpt' => astra_get_font_array_css( astra_get_option( 'related-posts-content-font-family' ), astra_get_option( 'related-posts-content-font-weight' ), $related_post_content_font_size, 'related-posts-content-font-extras', $related_post_text_color ),
'.ast-related-post-content .post-thumb-img-content img' => array(
'aspect-ratio' => $aspect_ratio,
'width' => $with_aspect_img_width,
'object-fit' => $object_fit, // setting it to 'cover' for custom ratio option same as blogs archive page.
),
'.ast-related-post-content .ast-author-avatar' => array(
'--ast-author-avatar-size' => astra_get_css_value( $author_avatar_size, 'px' ),
),
);
if ( astra_has_global_color_format_support() ) {
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
$related_posts_bg_color = astra_get_option( 'related-posts-background-color', $content_bg_obj );
if ( is_array( $related_posts_bg_color ) ) {
$css_desktop_output['.ast-single-related-posts-container'] = astra_get_responsive_background_obj( $related_posts_bg_color, 'desktop' );
} else {
$css_desktop_output['.ast-single-related-posts-container'] = array(
'background-color' => esc_attr( $related_posts_bg_color ),
);
}
}
$btn_text_color = astra_get_option( 'button-color', '#fff' );
$btn_border_color = astra_get_option( 'theme-button-border-group-border-color' );
$btn_border_h_color = astra_get_option( 'theme-button-border-group-border-h-color' );
$theme_color = astra_get_option( 'theme-color' );
$link_hover_color = astra_get_option( 'link-h-color' );
$btn_bg_color = astra_get_option( 'button-bg-color', $theme_color );
$btn_text_hover_color = astra_get_option( 'button-h-color', '#fff' );
$btn_bg_hover_color = astra_get_option( 'button-bg-h-color', $link_hover_color );
$btn_preset_style = astra_get_option( 'button-preset-style' );
$global_custom_button_border_size = astra_get_option( 'theme-button-border-group-border-size' );
if ( 'button_04' === $btn_preset_style || 'button_05' === $btn_preset_style || 'button_06' === $btn_preset_style ) {
if ( empty( $btn_border_color ) ) {
$btn_border_color = $btn_bg_color;
}
if ( '' === astra_get_option( 'button-bg-color' ) && '' === astra_get_option( 'button-color' ) ) {
$btn_text_color = $theme_color;
} elseif ( '' === astra_get_option( 'button-color' ) ) {
$btn_text_color = $btn_bg_color;
}
$btn_bg_color = 'transparent';
}
$css_desktop_output['.ast-related-cat-style--badge .cat-links > a, .ast-related-tag-style--badge .tags-links > a'] = array(
'border-style' => 'solid',
'border-top-width' => ( isset( $global_custom_button_border_size['top'] ) && '' !== $global_custom_button_border_size['top'] ) ? astra_get_css_value( $global_custom_button_border_size['top'], 'px' ) : '0',
'border-right-width' => ( isset( $global_custom_button_border_size['right'] ) && '' !== $global_custom_button_border_size['right'] ) ? astra_get_css_value( $global_custom_button_border_size['right'], 'px' ) : '0',
'border-left-width' => ( isset( $global_custom_button_border_size['left'] ) && '' !== $global_custom_button_border_size['left'] ) ? astra_get_css_value( $global_custom_button_border_size['left'], 'px' ) : '0',
'border-bottom-width' => ( isset( $global_custom_button_border_size['bottom'] ) && '' !== $global_custom_button_border_size['bottom'] ) ? astra_get_css_value( $global_custom_button_border_size['bottom'], 'px' ) : '0',
'padding' => '4px 8px',
'border-radius' => '3px',
'font-size' => 'inherit',
'color' => esc_attr( $btn_text_color ),
'border-color' => empty( $btn_border_color ) ? esc_attr( $btn_bg_color ) : esc_attr( $btn_border_color ),
'background-color' => esc_attr( $btn_bg_color ),
);
$css_desktop_output['.ast-related-cat-style--badge .cat-links > a:hover, .ast-related-tag-style--badge .tags-links > a:hover'] = array(
'color' => esc_attr( $btn_text_hover_color ),
'background-color' => esc_attr( $btn_bg_hover_color ),
'border-color' => empty( $btn_border_h_color ) ? esc_attr( $btn_bg_hover_color ) : esc_attr( $btn_border_h_color ),
);
$css_desktop_output['.ast-related-cat-style--underline .cat-links > a, .ast-related-tag-style--underline .tags-links > a'] = array(
'text-decoration' => 'underline',
);
$dynamic_css .= astra_parse_css( $css_desktop_output );
$css_max_tablet_output = array(
'.ast-single-related-posts-container .ast-related-posts-wrapper .ast-related-post' => array(
'width' => '100%',
),
'.ast-single-related-posts-container .ast-related-posts-wrapper' => array(
'grid-template-columns' => Astra_Builder_Helper::$grid_size_mapping[ $tablet_grid ],
),
'.ast-related-post-content .entry-header .ast-related-post-title, .ast-related-post-content .entry-header .ast-related-post-title a' => array(
'font-size' => astra_responsive_font( $related_post_title_font_size, 'tablet' ),
),
'.ast-related-post-content .entry-meta *' => array(
'font-size' => astra_responsive_font( $related_post_meta_font_size, 'tablet' ),
),
'.ast-related-post-excerpt' => array(
'font-size' => astra_responsive_font( $related_post_content_font_size, 'tablet' ),
),
'.ast-related-posts-title' => array(
'font-size' => astra_responsive_font( $related_posts_section_title_font_size, 'tablet' ),
),
);
if ( astra_has_global_color_format_support() ) {
if ( is_array( $related_posts_bg_color ) ) {
$css_max_tablet_output['.ast-single-related-posts-container'] = astra_get_responsive_background_obj( $related_posts_bg_color, 'desktop' );
} else {
$css_max_tablet_output['.ast-single-related-posts-container'] = array(
'background-color' => esc_attr( $related_posts_bg_color ),
);
}
}
$dynamic_css .= astra_parse_css( $css_max_tablet_output, '', astra_get_tablet_breakpoint() );
$css_max_mobile_output = array(
'.ast-single-related-posts-container .ast-related-posts-wrapper' => array(
'grid-template-columns' => Astra_Builder_Helper::$grid_size_mapping[ $mobile_grid ],
),
'.ast-related-post-content .entry-header .ast-related-post-title, .ast-related-post-content .entry-header .ast-related-post-title a' => array(
'font-size' => astra_responsive_font( $related_post_title_font_size, 'mobile' ),
),
'.ast-related-post-content .entry-meta *' => array(
'font-size' => astra_responsive_font( $related_post_meta_font_size, 'mobile' ),
),
'.ast-related-post-excerpt' => array(
'font-size' => astra_responsive_font( $related_post_content_font_size, 'mobile' ),
),
'.ast-related-posts-title' => array(
'font-size' => astra_responsive_font( $related_posts_section_title_font_size, 'mobile' ),
),
);
if ( astra_has_global_color_format_support() ) {
if ( is_array( $related_posts_bg_color ) ) {
$css_max_mobile_output['.ast-single-related-posts-container'] = astra_get_responsive_background_obj( $related_posts_bg_color, 'desktop' );
} else {
$css_max_mobile_output['.ast-single-related-posts-container'] = array(
'background-color' => esc_attr( $related_posts_bg_color ),
);
}
}
$dynamic_css .= astra_parse_css( $css_max_mobile_output, '', astra_get_mobile_breakpoint() );
$dynamic_css .= Astra_Extended_Base_Dynamic_CSS::prepare_inner_section_advanced_css( 'ast-sub-section-related-posts', '.site .ast-single-related-posts-container' );
return $dynamic_css;
}
return $dynamic_css;
}

View File

@@ -0,0 +1,132 @@
<?php
/**
* Related Posts - Static CSS
*
* @package astra
*
* @since 3.5.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
add_filter( 'astra_dynamic_theme_css', 'astra_related_posts_static_css', 11 );
/**
* Related Posts - Static CSS
*
* @param string $dynamic_css Astra Dynamic CSS.
* @return String Generated dynamic CSS for Related Posts.
*
* @since 3.5.0
*/
function astra_related_posts_static_css( $dynamic_css ) {
if ( astra_target_rules_for_related_posts() ) {
$dynamic_css .= '
.ast-related-post-title, .entry-meta * {
word-break: break-word;
}
.ast-related-post-cta.read-more .ast-related-post-link {
text-decoration: none;
}
.ast-page-builder-template .ast-related-post .entry-header, .ast-related-post-content .entry-header, .ast-related-post-content .entry-meta {
margin: 1em auto 1em auto;
padding: 0;
}
.ast-related-posts-wrapper {
display: grid;
grid-column-gap: 25px;
grid-row-gap: 25px;
}
.ast-related-posts-wrapper .ast-related-post, .ast-related-post-featured-section {
padding: 0;
margin: 0;
width: 100%;
position: relative;
}
.ast-related-posts-inner-section {
height: 100%;
}
.post-has-thumb + .entry-header, .post-has-thumb + .entry-content {
margin-top: 1em;
}
.ast-related-post-content .entry-meta {
margin-top: 0.5em;
}
.ast-related-posts-inner-section .post-thumb-img-content {
margin: 0;
position: relative;
}
';
if ( true === astra_check_is_structural_setup() ) {
/** @psalm-suppress InvalidOperand */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
$astra_mobile_breakpoint = astra_get_mobile_breakpoint();
/** @psalm-suppress InvalidOperand */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
$section_title_bottom_space = Astra_Dynamic_CSS::astra_4_6_0_compatibility() ? '20px' : '2em';
$dynamic_css .= '
.ast-single-related-posts-container {
border-top: 1px solid var(--ast-single-post-border, var(--ast-border-color));
}
.ast-separate-container .ast-single-related-posts-container {
border-top: 0;
}
.ast-single-related-posts-container {
padding-top: 2em;
}
.ast-related-posts-title-section {
padding-bottom: ' . $section_title_bottom_space . ';
}
.ast-page-builder-template .ast-single-related-posts-container {
margin-top: 0;
padding-left: 20px;
padding-right: 20px;
}
@media (max-width: ' . strval( $astra_mobile_breakpoint ) . 'px) {
.ast-related-posts-title-section {
padding-bottom: 1.5em;
}
}
';
} else {
$dynamic_css .= '
.ast-separate-container .ast-related-posts-title {
margin: 0 0 20px 0;
}
.ast-related-posts-title-section {
border-top: 1px solid #eeeeee;
}
.ast-related-posts-title {
margin: 20px 0;
}
.ast-page-builder-template .ast-related-posts-title-section, .ast-page-builder-template .ast-single-related-posts-container {
padding: 0 20px;
}
.ast-separate-container .ast-single-related-posts-container {
padding: 5.34em 6.67em;
}
.ast-single-related-posts-container {
margin: 2em 0;
}
.ast-separate-container .ast-related-posts-title-section, .ast-page-builder-template .ast-single-related-posts-container {
border-top: 0;
margin-top: 0;
}
@media (max-width: 1200px) {
.ast-separate-container .ast-single-related-posts-container {
padding: 3.34em 2.4em;
}
}
';
}
return $dynamic_css;
}
return $dynamic_css;
}