前提・実現したいこと
category.phpで投稿一覧を作っております。
発生している問題・エラーメッセージ
投稿記事内のaタグが別の場所にも自動で生成されてしまいます。
これを止めるにはどうしたらいいでしょうか。
記述コード
category.php
<?php get_header();?>
<div id="content">
<div id="newslist" class="clrFix"><!-- #ページ名 -->
<ul id="pankuzu" class="clrFix">
<li><a href="#"><img src="<?php echo esc_url(get_template_directory_uri());?>/shared/images/pankuzu_home.png"></a></li>
<li>></li>
<li>お知らせ</li>
</ul>
<h2><img src="<?php echo esc_url(get_template_directory_uri());?>/shared/images/newslist_title_01.png" alt="News"></h2>
<?php
$category = get_the_category();
$cat_name = $category[0]->cat_name; //カテゴリー名
$cat_slug = $category[0]->category_nicename; //スラッグ名
?>
<div id="main">
<div class="tabwrap">
<div class="tabinner">
<ul id="tab">
<li id="newstab"><h3><img src="<?php echo esc_url(get_template_directory_uri());?>/shared/images/newslist_ico_01_on.png" class="ico on">
<img src="<?php echo esc_url(get_template_directory_uri());?>/shared/images/newslist_ico_01_off.png" class="ico off" style="display:none;">News一覧</h3></li>
<li id="schooltab" class="center"><h3><img src="<?php echo esc_url(get_template_directory_uri());?>/shared/images/newslist_ico_02_on.png" class="ico on" style="display:none;">
<img src="<?php echo esc_url(get_template_directory_uri());?>/shared/images/newslist_ico_02_off.png" class="ico off">スクール情報</h3></li>
<li id="salontab"><h3><img src="<?php echo esc_url(get_template_directory_uri());?>/shared/images/newslist_ico_03_on.png" class="ico on" style="display:none;">
<img src="<?php echo esc_url(get_template_directory_uri());?>/shared/images/newslist_ico_03_off.png" class="ico off">サロン情報</h3></li>
</ul>
<!-- /#tab -->
<!-- #wrapper -->
<div id="wrapper">
<!-- .contents -->
<div class="contents">
<?php if(have_posts()): ?>
<?php while(have_posts()): ?>
<?php the_post(); ?>
<div class="content">
<img src="<?php echo esc_url(get_template_directory_uri());?>/shared/images/top_news_0<?php $category=get_the_category(); $cat_slug=$category[0]->category_nicename; if($cat_slug=='news'){echo "2";}elseif($cat_slug=='nailschool'){echo "3";}elseif($cat_slug=='nailsalon'){echo "1";}?>.png" class="newstag">
<p class="date"><?php the_time('Y/m/d'); ?></p>
<h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
<p class="text"><a href="<?php the_permalink(); ?>"><?php echo mb_substr($post->post_content,0, 100).'...';?></a></p>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
<!-- /.contents -->
<!-- .contents -->
<div class="contents">
<?php query_posts("cat=3"); ?>
<?php if(have_posts()): ?>
<?php while(have_posts()): ?>
<?php the_post(); ?>
<div class="content">
<img src="<?php echo esc_url(get_template_directory_uri());?>/shared/images/top_news_03.png" class="newstag">
<p class="date"><?php the_time('Y/m/d'); ?></p>
<h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
<p class="text"><a href="<?php the_permalink();?>"><?php echo mb_substr($post->post_content,0, 100).'...';?></a></p>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
</div>
<!-- /.contents -->
<!-- .contents -->
<div class="contents">
<?php query_posts("cat=4"); ?>
<?php if(have_posts()): ?>
<?php while(have_posts()): ?>
<?php the_post(); ?>
<div class="content">
<img src="<?php echo esc_url(get_template_directory_uri());?>/shared/images/top_news_01.png" class="newstag">
<p class="date"><?php the_time('Y/m/d'); ?></p>
<h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
<p class="text"><a href="<?php the_permalink();?>"><?php echo mb_substr($post->post_content,0, 100).'...';?></a></p>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
</div>
<!-- /.contents -->
</div><!-- /#wrapper -->
</div><!-- /#tabinner -->
</div><!-- /#tabwrapper -->
</div><!-- #main -->
</div><!-- #ページ名 -->
</div><!-- #content -->
<?php get_footer();?>
該当部分のソース
<div class="contents">
<div class="content">
<img src="http://xxxx/wp-content/themes/xxxx/shared/images/top_news_02.png" class="newstag">
<p class="date">2016/05/29</p>
<h4><a href="http://xxxx/news/%e4%bd%b5%e8%a8%ad%e3%83%8d%e3%82%a4%e3%83%ab%e3%82%b5%e3%83%ad%e3%83%b3%e5%90%8d%e5%a4%89%e6%9b%b4%e3%81%ae%e3%81%94%e6%a1%88%e5%86%85/">タイトル</a></h4>
<p class="text"><a href="http://xxxx/news/%e4%bd%b5%e8%a8%ad%e3%83%8d%e3%82%a4%e3%83%ab%e3%82%b5%e3%83%ad%e3%83%b3%e5%90%8d%e5%a4%89%e6%9b%b4%e3%81%ae%e3%81%94%e6%a1%88%e5%86%85/"><p>本文</a></p>
</div>
<div class="content">
<img src="http://xxxx/wp-content/themes/xxxx/shared/images/top_news_02.png" class="newstag">
<p class="date">2016/05/18</p>
<h4><a href="http://xxxx/news/%e6%a0%a1%e8%88%8e%e7%a7%bb%e8%bb%a2%e3%81%ae%e3%81%94%e6%a1%88%e5%86%85/">タイトル</a></h4>
<p class="text"><a href="http://xxxx/news/%e6%a0%a1%e8%88%8e%e7%a7%bb%e8%bb%a2%e3%81%ae%e3%81%94%e6%a1%88%e5%86%85/"><p>本文</a></p>
</div>
<div class="content">
<img src="http://xxxx/wp-content/themes/xxxx/shared/images/top_news_02.png" class="newstag">
<p class="date">2016/05/02</p>
<h4><a href="http://xxxx/news/%e5%88%9d%e5%bf%83%e8%80%85%e3%81%a7%e3%82%82%e5%a4%a7%e4%b8%88%e5%a4%ab%e2%98%86-%ef%bc%91day%e3%80%90%e3%82%bb%e3%83%ab%e3%83%95%e3%83%8d%e3%82%a4%e3%83%ab%e4%bd%93%e9%a8%93%e3%83%ac%e3%83%83/">タイトル</a></h4>
<p class="text"><a href="http://xxxx/news/%e5%88%9d%e5%bf%83%e8%80%85%e3%81%a7%e3%82%82%e5%a4%a7%e4%b8%88%e5%a4%ab%e2%98%86-%ef%bc%91day%e3%80%90%e3%82%bb%e3%83%ab%e3%83%95%e3%83%8d%e3%82%a4%e3%83%ab%e4%bd%93%e9%a8%93%e3%83%ac%e3%83%83/"><p><a href="http://ameblo.jp/xxxxtry-12153897623.html">本文</a></p>
</div>
<div class="content">
<img src="http://xxxx/wp-content/themes/xxxx/shared/images/top_news_02.png" class="newstag">
<p class="date">2016/05/02</p>
<h4><a href="http://xxxx/news/%e3%80%90%e5%b9%b3%e6%97%a5%e6%98%bc%e5%89%b2%e3%80%91%e3%83%bb%e3%80%90%e3%81%a8%e3%82%82%e5%89%b2%e3%80%91%e3%81%ae%e3%81%94%e6%a1%88%e5%86%85/">タイトル</a></h4>
<p class="text"><a href="http://xxxx/news/%e3%80%90%e5%b9%b3%e6%97%a5%e6%98%bc%e5%89%b2%e3%80%91%e3%83%bb%e3%80%90%e3%81%a8%e3%82%82%e5%89%b2%e3%80%91%e3%81%ae%e3%81%94%e6%a1%88%e5%86%85/"><p>本文<a href="http://ameblo.jp/xxxxtry-12146682084.html">本文リンクテキスト</a></p...</a></p>
</div>
<div class="content">
<img src="http://xxxx/wp-content/themes/xxxx/shared/images/top_news_02.png" class="newstag">
<p class="date">2016/05/02</p>
<h4><a href="http://xxxx/news/%ef%bd%87%ef%bd%97%e3%82%ad%e3%83%a3%e3%83%b3%e3%83%9a%e3%83%bc%e3%83%b3%e5%ae%9f%e6%96%bd%e4%b8%ad%ef%bc%81/">タイトル</a></h4>
<p class="text"><a href="http://xxxx/news/%ef%bd%87%ef%bd%97%e3%82%ad%e3%83%a3%e3%83%b3%e3%83%9a%e3%83%bc%e3%83%b3%e5%ae%9f%e6%96%bd%e4%b8%ad%ef%bc%81/"><p>本文<a href="http://ameblo.jp/xxxxtry-12154802979.html">本文リンクテキスト</a...</a></p>
</div>
</div>
<!-- /.contents -->
-
気になる質問をクリップする
クリップした質問は、後からいつでもマイページで確認できます。
またクリップした質問に回答があった際、通知やメールを受け取ることができます。
クリップを取り消します
-
良い質問の評価を上げる
以下のような質問は評価を上げましょう
- 質問内容が明確
- 自分も答えを知りたい
- 質問者以外のユーザにも役立つ
評価が高い質問は、TOPページの「注目」タブのフィードに表示されやすくなります。
質問の評価を上げたことを取り消します
-
評価を下げられる数の上限に達しました
評価を下げることができません
- 1日5回まで評価を下げられます
- 1日に1ユーザに対して2回まで評価を下げられます
質問の評価を下げる
teratailでは下記のような質問を「具体的に困っていることがない質問」、「サイトポリシーに違反する質問」と定義し、推奨していません。
- プログラミングに関係のない質問
- やってほしいことだけを記載した丸投げの質問
- 問題・課題が含まれていない質問
- 意図的に内容が抹消された質問
- 過去に投稿した質問と同じ内容の質問
- 広告と受け取られるような投稿
評価が下がると、TOPページの「アクティブ」「注目」タブのフィードに表示されにくくなります。
質問の評価を下げたことを取り消します
この機能は開放されていません
評価を下げる条件を満たしてません
質問の評価を下げる機能の利用条件
この機能を利用するためには、以下の事項を行う必要があります。
- 質問回答など一定の行動
-
メールアドレスの認証
メールアドレスの認証
-
質問評価に関するヘルプページの閲覧
質問評価に関するヘルプページの閲覧
checkベストアンサー
+1
<p class="text"><a href="http://xxxx/news/(略)/"><p>本文</a></p>
この部分が問題ですね。
<?php echo mb_substr($post->post_content,0, 100).'...';?>
// を
<?php echo esc_html( mb_substr( $post->post_content, 0, 100 ) ).'...';?>
多分ですが、こうしたら良いと思います。
投稿
-
回答の評価を上げる
以下のような回答は評価を上げましょう
- 正しい回答
- わかりやすい回答
- ためになる回答
評価が高い回答ほどページの上位に表示されます。
-
回答の評価を下げる
下記のような回答は推奨されていません。
- 間違っている回答
- 質問の回答になっていない投稿
- スパムや攻撃的な表現を用いた投稿
評価を下げる際はその理由を明確に伝え、適切な回答に修正してもらいましょう。
15分調べてもわからないことは、teratailで質問しよう!
- ただいまの回答率 88.36%
- 質問をまとめることで、思考を整理して素早く解決
- テンプレート機能で、簡単に質問をまとめられる
質問への追記・修正、ベストアンサー選択の依頼
kei344
2016/06/11 15:48
「別の場所」とはどこでしょうか。出力されたHTMLとスクリーンショット、category.php全文を追記されたほうが回答を得られやすいと思います。
tomy
2016/06/11 18:11
アドバイスありがとうございます。追記いたしました。
kei344
2016/06/11 20:32
出力されたHTML(ブラウザで「ページのソースを表示」)を質問文に追記できますか?
tomy
2016/06/12 01:05
文字数の関係で一部分になってます。