ru-se.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

blog-options.php (6149B)


      1 <?php
      2 
      3 function materialis_add_blog_options( $section ) {
      4 	$priority = 1;
      5 
      6 	materialis_add_kirki_field( array(
      7 		'type'     => 'sectionseparator',
      8 		'label'    => esc_html__( 'Blog Settings', 'materialis' ),
      9 		'section'  => $section,
     10 		'settings' => "blog_section_settings_separator",
     11 		'priority' => $priority,
     12 	) );
     13 
     14 	materialis_add_kirki_field( array(
     15 		'type'     => 'checkbox',
     16 		'settings' => 'blog_use_homepage_header',
     17 		'label'    => esc_html__( 'Show front page header on blog page', 'materialis' ),
     18 		'section'  => $section,
     19 		'default'  => false,
     20 	) );
     21 
     22 	materialis_add_kirki_field( array(
     23 		'type'     => 'checkbox',
     24 		'settings' => 'blog_sidebar_enabled',
     25 		'label'    => esc_html__( 'Show blog sidebar', 'materialis' ),
     26 		'section'  => $section,
     27 		'default'  => true,
     28 	) );
     29 
     30 
     31 	materialis_add_kirki_field( array(
     32 		'type'     => 'checkbox',
     33 		'settings' => 'show_author_about_box',
     34 		'label'    => esc_html__( 'Show post author info in sidebar', 'materialis' ),
     35 		'section'  => $section,
     36 		'default'  => false,
     37 	) );
     38 
     39 	materialis_add_kirki_field( array(
     40 		'type'     => 'checkbox',
     41 		'settings' => 'show_single_item_title',
     42 		'label'    => esc_html__( 'Show post title in post page', 'materialis' ),
     43 		'section'  => $section,
     44 		'default'  => true,
     45 	) );
     46 
     47 	materialis_add_kirki_field( array(
     48 		'type'     => 'checkbox',
     49 		'settings' => 'blog_post_meta_enabled',
     50 		'label'    => esc_html__( 'Show post meta', 'materialis' ),
     51 		'section'  => $section,
     52 		'default'  => true,
     53 	) );
     54 
     55 	materialis_add_kirki_field( array(
     56 		'type'     => 'checkbox',
     57 		'settings' => 'blog_post_highlight_enabled',
     58 		'label'    => esc_html__( 'Highlight first post', 'materialis' ),
     59 		'section'  => $section,
     60 		'default'  => true,
     61 	) );
     62 
     63 	$posts_per_row = array();
     64 
     65 	foreach ( array( 1, 2, 3, 4, 6 ) as $class ) {
     66 		$posts_per_row[ $class ] = sprintf( _n( '%s item', '%s items', $class, "materialis" ), $class );
     67 	}
     68 
     69 	materialis_add_kirki_field( array(
     70 		'type'     => 'select',
     71 		'settings' => 'blog_posts_per_row',
     72 		'label'    => esc_html__( 'Posts per row', 'materialis' ),
     73 		'section'  => $section,
     74 		'default'  => 2,
     75 		'choices'  => $posts_per_row,
     76 	) );
     77 
     78 	materialis_add_kirki_field( array(
     79 		'type'     => 'checkbox',
     80 		'settings' => 'blog_posts_as_masonry_grid',
     81 		'label'    => esc_html__( 'Display posts as masonry grid', 'materialis' ),
     82 		'section'  => $section,
     83 		'default'  => true,
     84 	) );
     85 
     86 	materialis_add_kirki_field( array(
     87 		'type'        => 'checkbox',
     88 		'settings'    => 'blog_show_post_featured_image',
     89 		'label'       => esc_html__( 'Use blog/post featured image as hero background when available', 'materialis' ),
     90 		'description' => esc_html__( 'Must have inner pages hero background set to image, and blog page and/or post featured image added.',
     91 			'materialis' ),
     92 		'section'     => $section,
     93 		'priority'    => 3,
     94 		'default'     => true,
     95 	) );
     96 
     97 
     98 	materialis_add_kirki_field( array(
     99 		'type'     => 'checkbox',
    100 		'settings' => 'blog_show_post_thumb_placeholder',
    101 		'label'    => esc_html__( 'Show thumbnail placeholder', 'materialis' ),
    102 		'section'  => $section,
    103 		'default'  => true,
    104 	) );
    105 
    106 	materialis_add_kirki_field( array(
    107 		'type'            => 'color',
    108 		'label'           => esc_html__( 'Placeholder Background Color', 'materialis' ),
    109 		'section'         => $section,
    110 		'settings'        => 'blog_post_thumb_placeholder_color',
    111 		'default'         => materialis_get_theme_colors( 'color1' ),
    112 		'active_callback' => array(
    113 			array(
    114 				'setting'  => 'blog_show_post_thumb_placeholder',
    115 				'operator' => '==',
    116 				'value'    => true,
    117 			),
    118 		),
    119 		'transport'       => 'postMessage',
    120 		'js_vars'         => array(
    121 			array(
    122 				'element'  => "svg.materialis-post-list-item-thumb-placeholder rect",
    123 				'property' => 'fill',
    124 				'suffix'   => '!important',
    125 			),
    126 		),
    127 	) );
    128 
    129 }
    130 
    131 materialis_add_blog_options( 'blog_settings' );
    132 
    133 
    134 function materialis_show_post_meta_setting_filter( $value ) {
    135 
    136 	$value = materialis_get_theme_mod( 'blog_post_meta_enabled', $value );
    137 
    138 	return $value;
    139 }
    140 
    141 add_filter( 'materialis_show_post_meta', 'materialis_show_post_meta_setting_filter' );
    142 
    143 
    144 function materialis_posts_per_row_setting_filter( $value ) {
    145 
    146 	$value = materialis_get_theme_mod( 'blog_posts_per_row', $value );
    147 
    148 	return $value;
    149 }
    150 
    151 add_filter( 'materialis_posts_per_row', 'materialis_posts_per_row_setting_filter' );
    152 
    153 function materialis_archive_post_highlight_setting_filter( $value ) {
    154 
    155 	if ( ! materialis_is_modified() && is_front_page() ) {
    156 		return false;
    157 	}
    158 
    159 
    160 	$value = materialis_get_theme_mod( 'blog_post_highlight_enabled', $value );
    161 
    162 	return $value;
    163 }
    164 
    165 add_filter( 'materialis_archive_post_highlight', 'materialis_archive_post_highlight_setting_filter' );
    166 
    167 
    168 function materialis_blog_sidebar_enabled_setting_filter( $value ) {
    169 
    170 
    171 	$value = intval( materialis_get_theme_mod( 'blog_sidebar_enabled', $value ) );
    172 
    173 	return ( $value === 1 );
    174 }
    175 
    176 add_filter( 'materialis_blog_sidebar_enabled', 'materialis_blog_sidebar_enabled_setting_filter' );
    177 
    178 
    179 function materialis_blog_posts_as_masonry_grid_data_script( $data ) {
    180 	$blog_uses_masonry = materialis_get_theme_mod( 'blog_posts_as_masonry_grid', true );
    181 
    182 	$data['blog_posts_as_masonry_grid'] = ! ! intval( $blog_uses_masonry );
    183 
    184 	return $data;
    185 }
    186 
    187 add_filter( 'materialis_theme_data_script', 'materialis_blog_posts_as_masonry_grid_data_script' );
    188 
    189 
    190 function materialis_is_blog_page_with_front_header() {
    191 	$value = false;
    192 
    193 	$use_front_header_on_blog_page = ! ! intval( materialis_get_theme_mod( 'blog_use_homepage_header', false ) );
    194 
    195 	if ( is_archive() || ( ! is_front_page() && is_home() ) ) {
    196 		if ( $use_front_header_on_blog_page ) {
    197 			$value = true;
    198 		}
    199 	}
    200 
    201 	return $value;
    202 }
    203 
    204 
    205 function materialis_header_blog_page_with_front_hero_filter( $header ) {
    206 
    207 	if ( materialis_is_blog_page_with_front_header() ) {
    208 		$header = "homepage";
    209 	}
    210 
    211 	return $header;
    212 }
    213 
    214 add_filter( 'materialis_header', 'materialis_header_blog_page_with_front_hero_filter' );
    215 
    216 
    217 function materialis_is_front_page_for_blog_page( $value ) {
    218 
    219 	if ( materialis_is_blog_page_with_front_header() ) {
    220 		$value = true;
    221 	}
    222 
    223 	return $value;
    224 }
    225 
    226 add_filter( 'materialis_is_front_page', 'materialis_is_front_page_for_blog_page' );