0

My mother tongue is not English. Here I use Google translation.

I need to display the first video of the article on the home page.

The following code is used

But I have a question.Does this server have query pressure?

function catch_post_video($postid=0,$which=0){
    $content = get_post($postid)->post_content;  
    preg_match_all('/<video.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
    if( $which==0 ){
        $output = ( $strResult && isset($strResult[1]) )?count($strResult[1]):0;
    }else if( $which==1 ){
        $img_url = get_stylesheet_directory_uri().'/images/default.png';
        $output = ( $strResult && !empty($strResult[1]) && !empty($strResult[1][0]) ) ? $strResult[1][0] : $img_url;
    }
    return $output;  
}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.