Last active
June 22, 2019 06:12
-
-
Save eto4detak/a2c4cbe78f3b26c4c3263b096883b3c1 to your computer and use it in GitHub Desktop.
wp php shortcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// shortcode ценовой диапозон | |
add_shortcode( 'divi_price_cat', 'divi_price_cat_shortcode' ); | |
function divi_price_cat_shortcode( $atts ){ | |
$cur_queried_object = get_queried_object(); | |
echo '<pre class="aaa" style="display:none">'; | |
var_dump( $cur_queried_object ); | |
echo '</pre>'; | |
// белый список параметров и значения по умолчанию | |
$atts = shortcode_atts( array( | |
'foo' => 'no foo', | |
'baz' => 'default baz' | |
), $atts ); | |
return "<strong>Диапазон цен:</strong> от 1000 до 4000 за м2"; | |
} | |
// шорткод кортинка поста | |
add_shortcode( 'image_marafon_post', 'marafon_image_post' ); | |
function marafon_image_post( $atts ){ | |
global $post; | |
$path = wp_upload_dir()['baseurl']. '/pic/'; | |
// nophoto.png | |
$marafon_user_title = get_post_meta($post->ID, 'marafon_user_title', 1); | |
$title = $marafon_user_title; | |
if(empty($marafon_user_title)){ | |
return '<img class="alignleft" src="'.$path.'nophoto.png" alt="" width="225" height="300" />'; | |
}else{ | |
$marafon_user_title = strtolower($marafon_user_title); | |
$marafon_user_title = str_replace(' ', '_', $marafon_user_title); | |
$filename = $path.$marafon_user_title.'/0.jpg'; | |
if (file_exists($filename)) { | |
return '<img class="alignleft" src="'.$filename.'" alt="'.$title.'" width="225" height="300" />'; | |
} else { | |
return '<img class="alignleft" src="'.$path.'nophoto.png" alt="'.$title.'" width="225" height="300" />'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment