Example #1
0
 function url_to_blog_card_tag($url)
 {
     if (!$url) {
         return;
     }
     $url = strip_tags($url);
     //URL
     $id = url_to_postid($url);
     //IDを取得(URLから投稿ID変換)
     if (!$id) {
         return;
     }
     //IDを取得できない場合はループを飛ばす
     global $post;
     $post_id = get_post($id);
     setup_postdata($post_id);
     $exce = $post_id->post_excerpt;
     $title = $post_id->post_title;
     //タイトルの取得
     $date = mysql2date('Y-m-d H:i', $post_id->post_date);
     //投稿日の取得
     $excerpt = get_content_excerpt($post_id->post_content, get_excerpt_length());
     //抜粋の取得
     if (is_wordpress_excerpt() && $exce) {
         //Wordpress固有の抜粋のとき
         $excerpt = $exce;
     }
     //新しいタブで開く場合
     $target = is_blog_card_target_blank() ? ' target="_blank"' : '';
     //$hatebu_url = preg_replace('/^https?:\/\//i', '', $url);
     //はてブを表示する場合
     $hatebu_tag = is_blog_card_hatena_visible() ? '<div class="blog-card-hatebu"><a href="//b.hatena.ne.jp/entry/' . $url . '"' . $target . '><img src="//b.hatena.ne.jp/entry/image/' . $url . '" alt="はてブ数" /></a></div>' : '';
     //サイトロゴを表示する場合
     $favicon_tag = '';
     if (is_favicon_enable() && get_the_favicon_url()) {
         //ファビコンが有効か確認
         //ファビコンをイメージたいのでそのまま表示する
         //$favicon_tag = '<span class="blog-card-favicon"><img src="'.get_the_favicon_url().'" class="blog-card-favicon-img" alt="ファビコン" /></span>';
         //はてなファビコンAPIを利用する
         //$favicon_tag = '<span class="blog-card-favicon"><img src="http://favicon.st-hatena.com/?url='.site_url().'" class="blog-card-favicon-img" alt="ファビコン" /></span>';
         //GoogleファビコンAPIを利用する
         //http://www.google.com/s2/favicons?domain=nelog.jp
         $favicon_tag = '<span class="blog-card-favicon"><img src="http://www.google.com/s2/favicons?domain=' . get_this_site_domain() . '" class="blog-card-favicon-img" alt="ファビコン" /></span>';
     }
     $site_logo_tag = is_blog_card_site_logo_visible() ? '<div class="blog-card-site">' . $favicon_tag . '<a href="' . home_url() . '"' . $target . '>' . get_this_site_domain() . '</a></div>' : '';
     $date_tag = '';
     if (is_blog_card_date_visible()) {
         $date_tag = '<div class="blog-card-date">' . $date . '</div>';
     }
     //サムネイルの取得(要100×100のサムネイル設定)
     $thumbnail = get_the_post_thumbnail($id, 'thumb100', array('class' => 'blog-card-thumb-image', 'alt' => $title));
     if (!$thumbnail) {
         //サムネイルが存在しない場合
         $thumbnail = '<img src="' . get_template_directory_uri() . '/images/no-image.png" alt="' . $title . '" class="blog-card-thumb-image" />';
     }
     //取得した情報からブログカードのHTMLタグを作成
     $tag = '<div class="blog-card internal-blog-card"><div class="blog-card-thumbnail"><a href="' . $url . '" class="blog-card-thumbnail-link"' . $target . '>' . $thumbnail . '</a></div><div class="blog-card-content"><div class="blog-card-title"><a href="' . $url . '" class="blog-card-title-link"' . $target . '>' . $title . '</a></div><div class="blog-card-excerpt">' . $excerpt . '</div></div><div class="blog-card-footer">' . $site_logo_tag . $hatebu_tag . $date_tag . '</div></div>';
     return $tag;
 }
Example #2
0
function get_the_custom_excerpt($content, $length = 70, $is_card = false)
{
    global $post;
    if (is_wordpress_excerpt() && $post->post_excerpt) {
        //Wordpress固有の抜粋文を使用するとき
        return $post->post_excerpt;
    } else {
        //Simplicity固有の抜粋文を使用するとき
        //if ( !ctype_digit($length) ) $length = 70;
        //$length = ( $length ? $length : 70 );//デフォルトの長さを指定する
        // $content =  preg_replace('/<!--more-->.+/is', '', $content); //moreタグ以降削除
        // $content =  strip_shortcodes($content);//ショートコード削除
        // $content =  strip_tags($content);//タグの除去
        // $content =  str_replace('&nbsp;', '', $content);//特殊文字の削除(今回はスペースのみ)
        // $content =  preg_replace('/\[.+?\]/i', '', $content); //ショートコードを取り除く
        // $content =  preg_replace(URL_REG, '', $content); //URLを取り除く
        // // $content =  preg_replace('/\s/iu',"",$content); //余分な空白を削除
        // $over    =  intval(mb_strlen($content)) > intval($length);
        // $content =  mb_substr($content, 0, $length);//文字列を指定した長さで切り取る
        // if ( get_excerpt_more() && $over ) {
        //   $content = $content.get_excerpt_more();
        // }
        // return $content;
        return get_content_excerpt($content, $length);
    }
}
Example #3
0
 function get_the_custom_excerpt($content, $length = 70, $is_card = false)
 {
     global $post;
     if (is_wordpress_excerpt() && $post->post_excerpt) {
         //Wordpress固有の抜粋文を使用するとき
         return $post->post_excerpt;
     } else {
         //Simplicity固有の抜粋文を使用するとき
         return get_content_excerpt($content, $length);
     }
 }