前提・実現したいこと
現在WordPressでTCDテーマを用いたテンプレートをカスタマイズしております。
新規投稿の一覧に、NEWの文字or画像を動的に表示させる方法を模索していますが
想定している要素の外に表示されてしまい行き詰っています。
想定している表示箇所と試したこと
上の画像にあるブログタイトル下のオレンジ色の破線部分にNEWの文字を表示させる事を想定しています。
しかし、私が書いているコードでは<span class="new_icon"></span>と、コードのみが反映され
肝心の文字がセクションの外に出て表示されてしまっています。
同じ個所にget_the_timeでタイムスタンプが表示されるか試したところ
こちらは想定しているオレンジ色の破線部分に表示されました。
想定している箇所に、NEWの文字を表示させるにはどうすればいいのでしょうか。
何卒ご教示のほどよろしくお願いいたします。
function.phpに記載したコード
function keika_awase($day,$limit){ global $wp_query; $days = 3; $today = date_i18n('U'); $entry_day = get_the_time('U'); $keika = date('U',($today - $entry_day)) / 86400; if ( $days > $keika ): $limit = 5; $num = $wp_query->current_post; if ( $limit > $num ): echo 'new'; endif; endif; }
上記内容を記述したい場所の全容
function theme_option_page_post_list() { global $post; $show_post_list = get_post_meta($post->ID, 'show_post_list', true); if(empty($show_post_list)) { $show_post_list = 'off'; } $options = get_design_plus_option(); if($show_post_list == 'on') { $post_num = $options['page_post_list_num']; $post_type = $options['page_post_list_type']; $post_order = $options['page_post_list_order']; if($post_order=='date2'){ $order = 'ASC'; } else { $order = 'DESC'; }; if($post_order=='date1'||$post_order=='date2'){ $post_order = 'date'; }; if($post_type == 'recent_post') { $args = array('post_type' => 'post', 'posts_per_page' => $post_num, 'ignore_sticky_posts' => 1, 'orderby' => $post_order, 'order' => $order); } else { $args = array('post_type' => 'post', 'posts_per_page' => $post_num, 'ignore_sticky_posts' => 1, 'orderby' => $post_order, 'order' => $order, 'meta_key' => $post_type, 'meta_value' => 'on'); }; $page_post_list = new WP_Query($args); if ($page_post_list->have_posts()) { $html = ''; $html .= '<div id="related_post">' . "\n"; $html .= '<h3 class="headline">' . $options['page_post_list_headline'] . "</h3>\n"; $html .= '<ol class="clearfix">' . "\n"; while ($page_post_list->have_posts()) : $page_post_list->the_post(); $html .= '<li class="clearfix">' . "\n"; if(has_post_thumbnail()) { $html .= '<a class="image" href="' . esc_url(get_the_permalink()) . '" title="' . esc_html(get_the_title()) . '">'; $html .= get_the_post_thumbnail($page_post_list->ID, 'size4'); $html .= "</a>\n"; } $html .= '<h4 class="title"><a href="' . esc_url(get_the_permalink()) . '" title="' . esc_html(get_the_title()) . '">' . trim_title_sc(30) . "</a></h4>\n"; $html .= '</li>' . "\n"; endwhile; wp_reset_query(); $html .= '</ol>' . "\n"; $html .= '</div>' . "\n"; echo $html; }; }; // show page post list }
記述したい場所のコード
$html .= '<h4 class="title"><a href="' . esc_url(get_the_permalink()) . '" title="' . esc_html(get_the_title()) . '">' . trim_title_sc(30) . "</a></h4>\n";
上記の「記述したい場所のコード」のすぐ下に記述したコード
$html .= '<span class="new_icon">' . keika_awase(get_the_time('U'),100,100) . "</span>\n";
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/07/04 00:04