'; } // ── Widget ──────────────────────────────────────────────────────────────────── class AdWol_Banner_Widget extends WP_Widget { public function __construct() { parent::__construct( 'adwol_banner_widget', __( 'AdWol Banner', 'adwol-werbung' ), [ 'description' => __( 'Responsives AdWol-Werbebanner (automatische Größenanpassung).', 'adwol-werbung' ) ] ); } public function widget( $args, $instance ): void { $tag = adwol_embed_tag( 'r' ); if ( ! $tag ) return; echo wp_kses( $args['before_widget'] ?? '', [ 'div' => [ 'class' => true, 'id' => true ] ] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo $tag; echo wp_kses( $args['after_widget'] ?? '', [ 'div' => [] ] ); } } add_action( 'widgets_init', function() { register_widget( 'AdWol_Banner_Widget' ); } ); // ── In-post ad injection ────────────────────────────────────────────────────── function adwol_inject_inpost( string $content ): string { if ( ! is_single() || strlen( $content ) < 500 ) return $content; $tag = adwol_embed_tag( 'r' ); if ( ! $tag ) return $content; $before = substr( $content, 0, 500 ); $after = substr( $content, 500 ); $parts = explode( '

', $after, 2 ); if ( count( $parts ) < 2 ) return $content; return $before . $parts[0] . '

' . $tag . $parts[1]; } if ( get_option( 'adwol_inpost_enabled', '1' ) === '1' ) { add_filter( 'the_content', 'adwol_inject_inpost' ); } // ── Related posts with ad ───────────────────────────────────────────────────── function adwol_related_posts( string $content ): string { if ( ! is_single() ) return $content; global $post, $adwol_related_cache; if ( isset( $adwol_related_cache ) ) { return $content . $adwol_related_cache; } $pid = $post->ID; $title = get_the_title(); $tags = wp_get_post_tags( $pid ); $tag_names = ''; $query_args = [ 'post__not_in' => [ $pid ], 'post_type' => 'post', 'posts_per_page' => 3, 'ignore_sticky_posts'=> 1, ]; if ( $tags ) { $tag_ids = wp_list_pluck( $tags, 'term_id' ); $tag_names = implode( ',', wp_list_pluck( $tags, 'name' ) ); $query_args['tag__in'] = $tag_ids; } else { $cats = get_the_category( $pid ); if ( $cats ) $query_args['cat'] = $cats[0]->cat_ID; } $rel_query = new WP_Query( $query_args ); if ( ! $rel_query->have_posts() ) { wp_reset_postdata(); return $content; } $html = '

' . esc_html__( 'Das könnte interessant sein', 'adwol-werbung' ) . ' ' . 'Powered by AdWol' . '

' . ''; $i = 0; while ( $rel_query->have_posts() ) { $rel_query->the_post(); // Inject ad between post 0 and post 1 if ( $i === 1 ) { $ad_tag = adwol_embed_tag( 'r', $tag_names, $title ); if ( $ad_tag ) { $html .= '
' . '
' . $ad_tag . '
' . ''; } } $post_content = get_the_content(); $excerpt = esc_html( wp_trim_words( wp_strip_all_tags( $post_content ), 20, '…' ) ); preg_match( '/]+src=[\'"](?P[^\'"]+)[\'"][^>]*>/i', $post_content, $img_match ); $img_src = ''; if ( ! empty( $img_match['src'] ) ) { $clean = preg_replace( '#^https?://#', '', $img_match['src'] ); $img_src = 'https://images.weserv.nl/?w=75&h=75&fit=cover&url=' . rawurlencode( $clean ); } if ( ! $img_src ) { $img_src = 'https://images.weserv.nl/?w=75&h=75&fit=cover&url=' . rawurlencode( 'adwol.com/norel.jpg' ); } $permalink = esc_url( get_the_permalink() ); $post_title = esc_html( get_the_title() ); $html .= '' . '' . '' . ''; $i++; } $html .= '
' . '' . '' . '' . $post_title . '' . '

' . $excerpt . '

' . '
'; wp_reset_postdata(); $adwol_related_cache = $html; return $content . $html; } if ( get_option( 'adwol_related_enabled', '1' ) === '1' ) { add_filter( 'the_content', 'adwol_related_posts' ); } // ── Admin settings page ─────────────────────────────────────────────────────── add_action( 'admin_menu', function() { add_options_page( 'AdWol Werbung', 'AdWol Werbung', 'manage_options', 'adwol-werbung', 'adwol_settings_page' ); } ); add_action( 'admin_init', function() { register_setting( 'adwol_settings', 'adwol_publisher_id', [ 'sanitize_callback' => 'absint', 'default' => '' ] ); register_setting( 'adwol_settings', 'adwol_inpost_enabled', [ 'sanitize_callback' => 'sanitize_text_field', 'default' => '1' ] ); register_setting( 'adwol_settings', 'adwol_related_enabled', [ 'sanitize_callback' => 'sanitize_text_field', 'default' => '1' ] ); register_setting( 'adwol_settings', 'adwol_ad_size', [ 'sanitize_callback' => 'sanitize_text_field', 'default' => 'r' ] ); } ); function adwol_settings_page(): void { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Keine Berechtigung.', 'adwol-werbung' ) ); } $pid = adwol_publisher_id(); ?>

AdWolAdWol Werbung

Schnellstart:
  1. Registrieren Sie sich kostenlos unter adwol.com/login?mode=register.
  2. Ihre Publisher-ID finden Sie unter Benutzerbereich → Publisher → Einbettungs-Code.
  3. Geben Sie die Publisher-ID unten ein und speichern Sie.
  4. Aktivieren Sie die gewünschten Platzierungen und fügen Sie das Widget über Design → Widgets ein.

AdWol v · FAQ · Kontakt · Wir schließen Gewährleistung und Haftung aus. Nutzung auf eigene Gefahr.