2016-06-02 3 views
0

Ниже приведен код Мне нужно выполнить только сообщения, которые будут отправлены до определенной даты, например. 11 ноября 2015 г.Условное выполнение функции по дате даты

Я знаю, что это условие ... ELSE, но у меня нет идеи, как создать это условие. Любая помощь приветствуется ...

Так что/это WordPress/Мне нужно «форматировать» таким образом все сообщения до определенной даты, а все сообщения новее, то эта дата будет исключена из следующей функции:

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); 

ответ

0

Что-то вроде этого

function user_content_replace($content) 
{ 
    global $post; 
    if (strtotime($post->post_date) <= strtotime('11.11.2015')) 
    { 
     $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 
     return $output; 
    } 
    else 
    { 
     return $content; 
    } 
} 

add_filter('the_content', 'user_content_replace', 99); 
Смежные вопросы