5شعار ووردإعلانات AdSense أعلاه في الفقرة الأخيرة وظيفة

You may have noticed that we’ve tweaked how we dis­play our adsense ads. We wanted some small text-only ads near the bot­tom of each art­icle, which would be added auto­mat­ic­ally. This took a little bit of tinker­ing, but even­tu­ally we developed a solu­tion which works well and does­n’t seem to knock page pro­cessing times much. Simply add the fol­low­ing code to your theme’s functions.php (لا تحصل على مقابل لتغيير معرفات في AdSense) 

Updated 12-Nov-2017 as the code was­n’t work­ing cor­rectly as pre­vi­ously dis­played. لقد أضاف أيضا 2 oth­er func­tions that I use, one to insert adverts via short­code, and anoth­er to add an advert where the more is removed when a post is shown in full

/************************************************************************\
* كود قصير AdSense للإدراج 2 إعلانات صغيرة في أي مكان عن طريق الرمز القصير *
\************************************************************************/
وظيفة Google_Adsense( $ATTS, $المحتوى = فارغة ) {
   إرجاع '<فئة شعبة ="ا" النمط ="مواءمة النصوص: مركز;"><شعبة معرف ="جوجل-1"></شعبة><أسلوب ص ="واضح: كلا"></ع></شعبة>';
}
add_shortcode('جوجل ادسنس', 'جوجل ادسنس');




/******************************************\
* تبين 2 إعلانات AdSense صغيرة في المزيد من البطاقات *
\******************************************/
add_filter('the_content', "adsense_added_at_more_tag");

// هذه الوظيفة محل المزيد العلامة مع رموز AdSense الخاص بك.
وظيفة adsense_added_at_more_tag($نص) {
إذا( is_single() ) :
$ads_text = '<شعبة معرف ="جوجل" الطبقة ="ا" النمط ="مواءمة النصوص: مركز;"><شعبة معرف ="جوجل-1"></شعبة><أسلوب ص ="واضح: كلا"></ع></شعبة>';
$pos1 = strpos($نص, '<فترة معرف ="أكثر من-');
//"
إذا($pos1 === FALSE) $النص = $ ads_text . $نص;
آخر
{
$pos2 = strpos($نص, '</شبر>', $pos1);
$text1 = SUBSTR($نص, 0, $pos1);
$text2 = SUBSTR($نص, $pos2+7);
$النص text1 = $ . $ads_text . $text2;
}
ENDIF;
عودة $ النص;
}




/*******************************************************\
* عرض واحد AdSense الإعلانية كبيرة فوق الفقرة الأخيرة *
\*******************************************************/
add_filter('the_content', "gads_added_above_last_para");

وظيفة gads_added_above_last_para($ytext) {
إذا( is_single() ) :
$yads_text = '<فئة شعبة ="ا" النمط ="مواءمة النصوص: مركز;"><شعبة معرف ="جوجل-2"></شعبة><أسلوب ص ="واضح: كلا"></ع></شعبة>';
إذا($ypos1 = strrpos($ytext, '</ع>')){
$ytext1 = SUBSTR($ytext, 0, ($ypos1 + 4));
$ytext2 = SUBSTR($ytext, ($ypos1 + 4));
$ytext = $ ytext1 . $yads_text . $ytext2;
}
ENDIF;
عودة $ ytext;
}

Leave a Reply

5 Comments

SJسارة جونز

I don’t know but your code was not work­ing in my case. لذا, I replaced it with oth­er code. If any­one else is facing the same prob­lem, then you can use the below code.

func­tion insert_ad_block( $نص ) {

إذا ( is_single() ) :

$ads_text = ‘My Ad Code Here’;
$split_by = “n”;
$insert_after = 2; //number of paragraphs

// make array of paragraphs
$para­graphs = explode( $split_by, $نص);

// if array ele­ments are less than $insert_after set the insert point at the end
$ليون = العد( $para­graphs );
إذا ( $فقط < $insert_after ) $insert_after = $ ليون;

// insert $ads_text into the array at the spe­cified point
array_splice( $para­graphs, $insert_after, 0, $ads_text );

// حلقة من خلال مجموعة وسلسلة بناء للإخراج
foreach( $para­graphs as $para­graph ) {
$new_text .= $para­graph;
}

عودة $ NEW_TEXT;

ENDIF;

عودة $ النص;

}
add_filter(‘the_content’, ‘insert_ad_block’);

الرد
MSماثيو سنايدر

هل هناك طريقة للقيام بذلك القول بعد 2الثانية الفقرة الرسم البياني بدلا من قبل آخر واحد?

الرد
JSJon Scaife

Abso-lutely. سوف تحتاج فقط إلى قرص رمز قليلا. أنا باستخدام strrpos الذي يجد في الماضي تحدث-RENCE من <p>
إذا أردت العثور على الثانية تحدث-RENCE من <p> استبدال خط 13 من التعليمات البرمجية أعلاه مع ...

إذا($pos1 = strpos($نص, '<ع>', strpos($نص, '<ع>') + 3)){
الرد
JSJon Scaife

بالتأكيد. إضافة بضع <ساعة />'ق - 1 at the start of the value of $ads_text and the oth­er at the end.
E.g. استبدل

$ads_text = '<فئة شعبة ="ا" النمط ="مواءمة النصوص: مركز;"><نوع النصي ="نص / جافا سكريبت"><!--
            google_ad_client = "كاليفورنيا حانة-0754629982287605";
            /* DMH-PostsMini */            google_ad_slot = "5138459326";
            google_ad_width = 468;
            google_ad_height = 15;
            //-->
            </سيناريو>
            <نوع النصي ="نص / جافا سكريبت" SRC ="https://pagead2.googlesyndication.com/pagead/show_ads.js">
            </سيناريو></شعبة>';

مع

$ads_text = '<ساعة /><فئة شعبة ="ا" النمط ="مواءمة النصوص: مركز;"><نوع النصي ="نص / جافا سكريبت"><!--
            google_ad_client = "كاليفورنيا حانة-0754629982287605";
            /* DMH-PostsMini */            google_ad_slot = "5138459326";
            google_ad_width = 468;
            google_ad_height = 15;
            //-->
            </سيناريو>
            <نوع النصي ="نص / جافا سكريبت" SRC ="https://pagead2.googlesyndication.com/pagead/show_ads.js">
            </سيناريو></شعبة><ساعة />';
الرد