[CR]Adsense Custom Placement

Here you can set your custom placement for adsense.

FEATURES

Adsense Placement(s)

'', 'post_count' => '', 'adsense_code' => '', 'block_note' => '', ); for($idx = 0; $idx <= $counter; $idx++) { $block = isset( $configs[ $idx ] ) ? $configs[ $idx ] : $default_block; ?>

"; //echo "\$wp_query->current_post: $wp_query->current_post
"; $configs = get_option('cr_adsense_cp_configurations', array()); $counter = isset( $configs['counter'] ) ? $configs['counter'] : 0; $default_block = array( 'option' => '', 'post_count' => '', 'adsense_code' => '', 'block_note' => '', ); $current_post = $wp_query->current_post + 1; $post_type = $wp_query->posts[ $wp_query->current_post ]->post_type; $switch_type = ''; if( in_array( $post_type, array('post', 'page') ) ) { $switch_type = $post_type; } for($idx = 0; $idx <= $counter; $idx++) { $block = isset( $configs[ $idx ] ) ? $configs[ $idx ] : $default_block; //print_r($block); if('above ' . $switch_type == $block[ 'option' ]) { if($current_post == $block[ 'post_count' ]) { $content = $block[ 'adsense_code' ] . $content; } } else if('below ' . $switch_type == $block[ 'option' ]) { if($current_post == $block[ 'post_count' ]) { $content .= $block[ 'adsense_code' ]; } } } return $content; } add_filter('the_title', 'cr_adsense_cp_filter_the_title', 1); function cr_adsense_cp_filter_the_title($content) { global $wp_query; //echo "\$wp_query->current_post: $wp_query->current_post
"; $configs = get_option('cr_adsense_cp_configurations', array()); $counter = isset( $configs['counter'] ) ? $configs['counter'] : 0; $default_block = array( 'option' => '', 'post_count' => '', 'adsense_code' => '', 'block_note' => '', ); $current_post = $wp_query->current_post + 1; $post_type = $wp_query->posts[ $wp_query->current_post ]->post_type; $switch_type = ''; if( in_array( $post_type, array('post', 'page') ) ) { $switch_type = $post_type; } for($idx = 0; $idx <= $counter; $idx++) { $block = isset( $configs[ $idx ] ) ? $configs[ $idx ] : $default_block; $adsense_code = $block[ 'adsense_code' ]; //print_r($block); if('above title ' . $switch_type == $block[ 'option' ]) { if($current_post == $block[ 'post_count' ]) { if(trim( $adsense_code ) == '') continue; if( !is_single() ) $content = "" . $adsense_code . "" . $content . ""; else $content = $adsense_code . $content; } } else if('below title ' . $switch_type == $block[ 'option' ]) { if(trim( $adsense_code ) == '') continue; if($current_post == $block[ 'post_count' ]) { if( !is_single() ) $content .= "" . $adsense_code; else $content .= $adsense_code; } } } return $content; } class CR_Adsense_CP extends WP_Widget { function CR_Adsense_CP() { parent::WP_Widget('', $name = '[CR]Adsense CP'); } function widget($args, $instance) { extract( $args ); $title = apply_filters('widget_title', $instance['title']); echo $before_widget; if ( $title ) echo $before_title . $title . $after_title; echo $instance['adsense_code']; echo $after_widget; } function update($new_instance, $old_instance) { $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); $instance['adsense_code'] = strip_tags($new_instance['adsense_code']); return $instance; } function form( $instance ) { global $wpdb; $title = esc_attr($instance['title']); $adsense_code = esc_attr($instance['adsense_code']); ?>