Created
July 30, 2020 19:29
-
-
Save djmtype/920cbe9dee453b9fb51438b32255a545 to your computer and use it in GitHub Desktop.
AdSanity general ad template
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 | |
if ( ! defined( 'ABSPATH' ) ) { die( 'You are not allowed to call this file directly.' ); } | |
global $post; | |
$ad_id = get_the_ID(); | |
$ad_target = get_post_meta( $ad_id, '_target', true ); | |
$ad_permalink = get_permalink( $ad_id ); | |
$ad_size = get_post_meta( $ad_id, '_size', true ); | |
$classes = array( | |
sprintf( 'ad-%s', $ad_size ), | |
sprintf( 'adsanity-%s', $ad_size ) | |
); | |
// Set by the wrapper function that includes this file | |
// Do not include it if this is an ad group with columns | |
if ( isset( $align ) && ! isset( $num_columns ) ) { | |
$classes[] = esc_attr( $align ); | |
$classes[] = esc_attr( sprintf( 'adsanity-%s', $align ) ); | |
} | |
$adsanity_post_class = apply_filters( 'adsanity_post_class', $classes, $post ); | |
$adsanity_post_id = apply_filters( 'adsanity_post_id', sprintf( 'ad-%s', $ad_id ) ); | |
// Trigger custom code before the ad wrapper | |
do_action( 'adsanity_before_ad_wrapper', $post ); | |
?> | |
<div id="<?php echo esc_attr( $adsanity_post_id ); ?>" class="<?php echo esc_attr( implode( ' ', $adsanity_post_class ) ); ?>" <?php | |
if ( isset( $max_width ) && $max_width ) { | |
printf( 'style="max-width:%dpx"', intval( $max_width ) ); | |
} | |
?>> | |
<?php | |
$headline = get_field('ad_headline'); | |
$summary = get_field('ad_summary'); | |
$extra_info = get_field('ad_extra_info'); | |
$photo = wp_get_attachment_image(get_field('ad_photo'), 'large', 0, array( 'title' => '', 'class' => 'sponsor-photo', 'alt' => '')); | |
$logo = wp_get_attachment_image(get_field('ad_logo'), 'large', 0, array( 'title' => '', 'class' => 'sponsor-logo', 'alt' => '')); | |
$text_color = 'color:' . get_field('ad_text_color') . ';'; | |
$background_color = 'background-color:' . get_field('ad_background_color') . ';'; | |
?> | |
<?php | |
// Trigger custom code inside the wrapper, before the ad | |
do_action( 'adsanity_before_ad', $post ); ?> | |
<div class="sponsor-container" data-layout="more-photo" style="<?php if($background_color){ echo $background_color; } if($text_color) { echo $text_color; } ?>"> | |
<?php // Hosted Ad | |
if ( has_post_thumbnail( $ad_id ) ) { | |
echo sprintf( | |
'<a rel="nofollow" href="%s" %s>%s</a>', | |
esc_attr( esc_url( $ad_permalink ) ), | |
(bool) $ad_target ? ' target="_blank"' : '', | |
get_the_post_thumbnail( $ad_id, 'full' ) | |
); | |
?> | |
<?php } elseif($photo) { ?> | |
<?php echo sprintf( | |
'<a class="link-block" rel="nofollow noopener" href="%s" %s>%s</a>', | |
esc_attr( esc_url( $ad_permalink ) ), | |
(bool) $ad_target ? ' target="_blank"' : '','' | |
); ?> | |
<?php if($photo) { ?> | |
<div class="sponsor-thumb"><?php echo $photo; ?></div> | |
<div class="sponsor-content flow-lg-y"> | |
<div class="sponsor-content-main flow-xs-y"> | |
<?php if($headline) { ?> | |
<p class="h3 text-sans"><?php echo $headline; ?></p> | |
<?php } ?> | |
<?php if($summary) { ?> | |
<p class="h5"><?php echo $summary; ?></p> | |
<?php } ?> | |
</div> | |
<div class="sponsor-content-footer flow-xs-y"> | |
<?php if($logo) { ?> | |
<?php echo $logo; ?> | |
<?php } ?> | |
<?php if($extra_info) { ?> | |
<p class="h6"><?php echo $extra_info; ?></p> | |
<?php } ?> | |
</div> | |
</div> | |
<?php } // if photo ?> | |
<?php } else if ( $code = get_post_meta( $ad_id, '_code', true ) ) { | |
$code = str_replace( | |
array( | |
'%link%', | |
'[link]', | |
'[timestamp]', | |
), | |
array( | |
esc_attr( esc_url( $ad_permalink ) ), | |
esc_attr( esc_url( add_query_arg( 'r', '', $ad_permalink ) ) ), | |
esc_attr( time() ), | |
), | |
$code | |
); | |
echo $code; | |
} else if ( $text = get_post_meta( $ad_id, '_text', true ) ) { | |
$background_color = get_post_meta( $ad_id, '_text_bg', true ); | |
$border_color = get_post_meta( $ad_id, '_text_border', true ); | |
$border_width = get_post_meta( $ad_id, '_text_border_width', true ); | |
$style = ''; | |
if ( $background_color && '' !== $background_color ) { | |
$style .= sprintf( | |
'background-color:%s;', | |
$background_color | |
); | |
} | |
if ( $border_width && '' !== $border_width ) { | |
$style .= sprintf( | |
'border:1px solid %s;', | |
$border_color | |
); | |
} | |
if ( $border_color && '' !== $border_color ) { | |
$style .= sprintf( | |
'border-width:%spx;', | |
$border_width | |
); | |
} | |
printf( | |
'<div class="adsanity-text%s" style="%s;"><div>%s</div></div>', | |
get_post_meta( $ad_id, '_text_vertical', true ) ? ' adsanity-vertical-text' : '', | |
esc_attr( $style ), | |
$text | |
); | |
} else { | |
$ad_src = get_post_meta( $ad_id, 'ad_src', true ); | |
echo get_the_title(); | |
// printf( | |
// '<iframe src="%s" frameborder="0" scrolling="no"></iframe>', | |
// esc_attr( trailingslashit( $ad_src ) ) | |
// ); | |
} ?> | |
</div> | |
<?php // Trigger custom code inside the wrapper, after the ad | |
do_action( 'adsanity_after_ad', $post ); | |
?> | |
</div> | |
<?php | |
// Trigger custom code after the ad wrapper | |
do_action( 'adsanity_after_ad_wrapper', $post ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment