venerdì 30 marzo 2012

Funzioni per prendere e togliere il primo video del post

function catch_that_video() {
  global $post, $posts;
  $first_video = '';
  ob_start();
  ob_end_clean();
 

 $output = preg_match_all('/http:\/\/www.youtube.com\/watch\?v=(.+)&/', $post->post_content, $matches);

  $first_video = $matches[1][0];

  if(empty($first_video)){
    $first_video = "";
  }
  return $first_video;
}

function remove_first_video ($content) {
if (!is_page() && !is_feed() && !is_feed() && !is_home()) {
$content = preg_replace("/]+\>/i", "", $content, 1);
} return $content;
}

mercoledì 28 marzo 2012

funzioni per prendere e togliere la prima immagine del post

function catch_that_image() {
  global $post, $posts;
  $first_img = '';
  ob_start();
  ob_end_clean();
  $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].+>/i', $post->post_content, $matches);
  $first_img = $matches [1] [0];

  if(empty($first_img)){ //Defines a default image
    $first_img = "";
  }
  return $first_img;
}

function remove_first_image ($content) {
if (!is_page() && !is_feed() && !is_feed() && !is_home()) {
$content = preg_replace("/]+\>/i", "", $content, 1);
} return $content;
}
add_filter('the_content', 'remove_first_image');

lunedì 26 marzo 2012

templates wordpress

FILES

index.php si riferisce alla HOME
single.php si riferisce al singolo POST

FUNZIONI
the_content()  scrive tutto il contenuto
the_excerpt() scrive solo il teaser
the_date() scrive la data