WordPress in the article display ads not up and down, right and left corner

Source: Internet
Author: User
Keywords WordPress

Intermediary transaction http://www.aliyun.com/zixun/aggregation/6858.html ">seo diagnose Taobao guest cloud host technology Hall

See some websites before the ad output is very special, that is, in the text display ads, I said is not up and down, the left and right corner of the display method. To see the effect, you can look at the ads displayed in Bluefate's blog post. Because I'm not a program, but I know a little bit of PHP, so research for a while to write out a text in the output of advertising code:

<?php
Output the content of the article, when you encounter the first </p>, display ads
$form = 0;
$contents = Get_the_content ();
$lenght = Stripos ($contents, "</p>");//</p> to split character channeling and return in numeric form
$lenght = $lenght + ' 4 ', plus the number of characters in </p> station
$contents 1 = substr ($contents, $form, $lenght);//Intercept article
$contents 2 = substr ($contents, $lenght);
if (get_option (' Swt_adt ') = = ' Hide ' | | strlen ($contents) <= $lenght | | $lenght < 20) {//Output advertisement
The_content (");
}
else {
Echo $contents 1;//The first half of the output
Include TemplatePath. '/includes/adwz.php ');
Echo $contents the second half of 2;//output
}
?>

Save the above code for contents.php, the path in the template folder includes/contents.php, the article page single.php output when the article is replaced with the original < PHP the_content ("); >. Here to explain the code slightly, first use the get_the_content () function to get the content of the article, and then use the Stripos () function to return the specified string "</p>" position, and then use the substr () function to intercept the content into two parts; Finally through the judgment to display the advertisement, if the label </p> does not exist or the advertisement is hidden directly output the original article, otherwise output article before the paragraph + ads + the second half of the article. You can also use the number of judgments to display ads. Well, if you don't understand, you can contact me. Or have a good method, also please share, this article by Bluefate (http://www.bluefate.org/201205083039.html) original, welcome reprint, Thank you

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.