mercredi 1 juin 2016

Conditional execution of function by post date

Below is code I need to be executed just on posts till particular date, eg. November 11, 2015.

I know this is IF...ELSE condition, but I don't have an idea how to create this condition. Any kind of help is appreciated...

So in fact /this is WordPress/ I need to "format" in this way all posts till particular date, and all posts newer then that date will be excluded from function below:

function user_content_replace($content) {

$sentences_per_paragraph = 3; // settings

$pattern = '~(?<=[.?!…])\s+~'; // some punctuation and trailing space(s)

$sentences_array = preg_split($pattern, $content, -1, PREG_SPLIT_NO_EMPTY); // get sentences into array

$sentences_count = count($sentences_array); // count sentences

$output = ''; // new content init

// see PHP modulus
for($i = 0; $i < $sentences_count; $i++) {
    if($i%$sentences_per_paragraph == 0 && $i == 0) { //divisible by settings and is first
        $output .= "<p>" . $sentences_array[$i] . ' '; // add paragraph and the first sentence
    } elseif($i%$sentences_per_paragraph == 0 && $i > 0) { //divisible by settings and not first
        $output .= "</p><p>" . $sentences_array[$i] . ' '; // close and open paragraph, add the first sentence
    } else {
        $output .= $sentences_array[$i] . ' '; // concatenate other sentences
    }
}

$output .= "</p>"; // close the last paragraph

echo $output;
}
add_filter('the_content','user_content_replace', 99);

Aucun commentaire:

Enregistrer un commentaire