Get the App
SLTechnology News&Howtos  ›  Servers  › 

How WordPress displays ads in articles that have been published for more than 15 days

Shulou Source: shulou.com Published: 2022-06-02 04:59:49 09月10日 Update

This article is about how WordPress displays ads in articles that have been published for more than 15 days. The editor thought it was very practical, so I shared it with you as a reference. Let's follow the editor and have a look.

How does WordPress display ads in articles that have been published for more than 15 days?

WordPress displays ads in articles that have been published for more than 15 days.

Suppose we need to display ads in articles that have been published for more than 15 days, and we only need to set up the code to do it today.

Step one:

The function is easy to implement, using the PHP editor to open the functions.php file of the current template.

Copy the following code into it:

The code is as follows:

Function is_old_post ($post_id=null) {$days = 15; global $wp_query; if (is_single () | | is_page ()) {if (! $post_id) {$post_id= $wp_query- > post- > ID;} $current_date = time (); $offset = $days * 60mm 60mm 24; $post_id= get_post ($post_id); $post_date = mysql2date ('Upright Magnum postcards-> post_date); $cunning_math = $post_date + $offset; $test = $current_date-$cunning_math If ($test > 0) {$return = true;} else {$return = false;}} else {$return = false;} return $return;}

Step 2:

Open the single.php file and copy the following code in:

The code is as follows:

< ?php if(is_old_post()){ ?>

INSERT AD CODE HERE

< ?php } ?>

After the modification, the ad will only be displayed in the log with a release date of more than 15 days, which can be modified. In the code copied into functions.php, there is a sentence: $days= 15; here the value of $days=num; num can be set at will.

Thank you for reading! So much for the way WordPress displays ads in articles that have been published for more than 15 days. I hope the above content can be helpful to you, so that you can learn more knowledge. If you think the article is good, you can share it and let more people see it.

Tags: Ads articles time code methods content files more good practical features logs dates templates look knowledge articles editors references help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno vpn Huawei Shulou Technology Docker