function get_the_custom_excerpt($content, $length) { $length = ($length ? $length : 40); $content = strip_shortcodes($content); $content = strip_tags($content); $content = str_replace(" ","",$content); $content = trim($content); $content = mb_substr($content,0,$length); return $content; } function my_custom_single_popular_post( $post_html, $p, $instance ){ $img = get_field( '_wpp_thumbnail', $p->id, false); if......ここからわからないです(画面幅425以上の時){ $titlepc = mb_substr($p->title,0,20); if(mb_strlen($p->title) > 20)$title .= "…"; $expectpc = get_the_custom_excerpt(get_post_field('post_content',$p->id,'raw'),80); if(mb_strlen(get_the_custom_excerpt(get_post_field('post_content',$p->id,'raw'),80)) > 70)$expect .= "…" }; else{ $titlesp = mb_substr($p->title,0,15); if(mb_strlen($p->title) > 15)$title .= "…"; $expectsp = get_the_custom_excerpt(get_post_field('post_content',$p->id,'raw'),40); if(mb_strlen(get_the_custom_excerpt(get_post_field('post_content',$p->id,'raw'),40)) > 40)$expect .= "…" }; endif; $output .= '<li>'; $output .= '<a href="' . get_the_permalink($p->id) . '">'; $output .= '<img src="' . $img . '" alt="' . esc_attr($p->title) . '" />'; $output .= '<span class="f_right">'; $output .= '<p class="pc_wpp-title">' . esc_attr($title) . '</p>';//画面幅425以上の時に出力したい $output .= '<span class="pc_wpp-text">' . $expect . '</span>';//画面幅425以上の時に出力したい $output .= '<p class="pc_wpp-title">' . esc_attr($title) . '</p>';//画面幅425以下の時に出力したい $output .= '<span class="pc_wpp-text">' . $expect . '</span>';//画面幅425以下の時に出力したい $output .= '<span class="wpp_stats">'; $output .= '<span class="wpp_date">'. get_the_date("Y.m.d",$p->id) .'</span>'; $output .= '<span class="wpp_cat">'. get_the_category($p->id)[0]->name .'</span>'; $output .= '</span>'; $output .= '<img src="'.get_stylesheet_directory_uri().'/images/saisei_btn.png'.'" class="saisei_btn"/>'; $output .= '</span>'; $output .= '</a>'; $output .= '</li>'; return $output; } add_filter( 'wpp_post', 'my_custom_single_popular_post', 10, 3 );
このコードの $titlepcと $titlespの部分で条件を分岐させてたいのですが書き方がわかりません。
phpが詳しく分からないのでどなたか教えていただけませんでしょうか。よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/07/05 15:05