teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

4

header.phpの記述を追記しました

2020/05/13 04:13

投稿

yoshiaj
yoshiaj

スコア5

title CHANGED
@@ -1,1 +1,1 @@
1
- WordPressにて、スライダーに設定した記事リンク先が正常に機能しておらずに困っています。
1
+ WordPressにて、ヘッダーに記事スライダーを実装した後、記事リンク先が正常に機能しておらずに困っています。
body CHANGED
@@ -6,20 +6,56 @@
6
6
  飛び先のURLもブラウザのタブタイトルも正常に表示されているのですが、リンク先のコンテンツが全て最新記事で
7
7
  表示されてしまっています。
8
8
 
9
- 恐らく以下のコードが影響しているものだと考えています。
9
+ 恐らく以下のヘッダーに記事スライダー実装する際に記述したコードが影響しているものだと考えています。
10
- ループで記事を表示させて、そこにリンクを設置し、サムネイルとタイトルを取得しています。
11
10
 
12
- <?php the_permalink(); ?>
13
- ↑この箇所をもっと違う書き方にすればうまくいくのでしょうか?
14
- 技術不足でよくわからずにいます。
11
+ どなたかご教授ろしおねがます。
15
12
 
13
+ ### 該当のソースコード
14
+ ヘッダーに記事スライダーを設置するために書いたコード
15
+ 「header.php」に記載しています。自分で追記した箇所は<div class="your-class">~</div>の箇所になります。
16
- どなたよろしくおねがいします。
16
+ 文字数制限の関係で、途中ら途中での記載になります。
17
17
 
18
- ### 該当のソースコード
19
- ヘッダーに記事スライダーを設置するために書いたコードです。
20
- 「header.php」に記載しています。
21
18
  ```ここに言語を入力
19
+ <div id="container">
20
+ <!-- header -->
21
+ <?php if(!is_singular('lp') && !is_attachment() ): ?>
22
+ <!-- lpページでは表示しない -->
23
+ <div id="header" class="clearfix">
24
+ <?php $firstView_pos = get_option('diver_option_firstview_position',get_theme_mod('headerimage_position','bottom')); ?>
25
+ <?php if($firstView_pos == 'top'){get_template_part('/lib/parts/firstview');} ?>
26
+ <header class="header-wrap" role="banner" itemscope="itemscope" itemtype="http://schema.org/WPHeader">
27
+ <?php get_template_part('/lib/parts/miniheader'); ?>
28
+
29
+ <div class="header-logo clearfix">
30
+ <?php get_template_part('/lib/parts/sp','menu'); ?>
31
+
32
+ <!-- /Navigation -->
33
+ <div id="logo">
34
+ <?php $diverlogo = get_theme_mod("diver_logo"); ?>
35
+ <a href="<?php echo home_url('/'); ?>">
36
+ <?php if(empty($diverlogo)): ?>
37
+ <div class="logo_title"><?php bloginfo('name'); ?></div>
38
+ <?php else: ?>
39
+ <img src="<?php echo esc_url($diverlogo) ?>" alt="<?php bloginfo('name'); ?>">
40
+ <?php endif; ?>
41
+ </a>
42
+ </div>
43
+ <?php if(get_theme_mod('nav_style','in')=='in'): ?>
44
+ <nav id="nav" role="navigation" itemscope="itemscope" itemtype="http://scheme.org/SiteNavigationElement">
45
+ <?php wp_nav_menu( array (
46
+ 'theme_location' => 'header-navi',
47
+ 'items_wrap' => '<ul id="mainnavul" class="menu">%3$s</ul>',
48
+ 'link_before' => '',
49
+ 'link_after' => '',
50
+ 'depth' => 0,
51
+ 'fallback_cb' => ''
52
+ )); ?>
53
+ </nav>
54
+ <?php else:
55
+ (!is_mobile())?get_template_part('/lib/parts/header-right'):'';
56
+ endif; ?>
57
+ </div>
22
-        <div class="your-class">
58
+ <div class="your-class">
23
59
  <?php
24
60
  $args = array(
25
61
  'posts_per_page' => 9 // 表示件数の指定
@@ -39,6 +75,8 @@
39
75
  wp_reset_postdata(); // 直前のクエリを復元する
40
76
  ?>
41
77
  </div>
78
+ </header>
79
+
42
80
  ```
43
81
 
44
82
  飛び先(single.php)のコードです。文字制限にかかってしまうため途中からの記述は省いております。

3

質問文再編集しました。

2020/05/13 04:13

投稿

yoshiaj
yoshiaj

スコア5

title CHANGED
File without changes
body CHANGED
@@ -16,7 +16,8 @@
16
16
  どなたかよろしくおねがいします。
17
17
 
18
18
  ### 該当のソースコード
19
-
19
+ ヘッダーに記事スライダーを設置するために書いたコードです。
20
+ 「header.php」に記載しています。
20
21
  ```ここに言語を入力
21
22
         <div class="your-class">
22
23
  <?php

2

使用テーマと公式サイトを追記いたしました

2020/05/13 01:02

投稿

yoshiaj
yoshiaj

スコア5

title CHANGED
File without changes
body CHANGED
@@ -175,4 +175,7 @@
175
175
  <?php sharebtn(get_option('diver_sns_post_bottom_style',get_theme_mod('sharebtn_style_bottom','big')),'bottom'); ?>
176
176
  <?php get_template_part('/lib/parts/parts','author'); ?>
177
177
  </section>
178
- ```
178
+ ```
179
+
180
+ 使用テーマ:「diver」
181
+ 公式サイト:https://tan-taka.com/diver/

1

コードをコードブロックで囲い、飛び先ページのコードを追記(文字数制限の都合で途中から省略)

2020/05/13 00:41

投稿

yoshiaj
yoshiaj

スコア5

title CHANGED
File without changes
body CHANGED
@@ -17,7 +17,8 @@
17
17
 
18
18
  ### 該当のソースコード
19
19
 
20
+ ```ここに言語を入力
20
- <div class="your-class">
21
+        <div class="your-class">
21
22
  <?php
22
23
  $args = array(
23
24
  'posts_per_page' => 9 // 表示件数の指定
@@ -36,4 +37,142 @@
36
37
  endforeach; // ループの終了
37
38
  wp_reset_postdata(); // 直前のクエリを復元する
38
39
  ?>
39
- </div>
40
+ </div>
41
+ ```
42
+
43
+ 飛び先(single.php)のコードです。文字制限にかかってしまうため途中からの記述は省いております。
44
+ ```ここに言語を入力
45
+ <?php
46
+ global $post;
47
+
48
+ $position = get_theme_mod('sidebar_position_page','right');
49
+ $adremove = get_post_meta($post->ID, "ad_remove", true);
50
+
51
+ $pickup_tag = get_theme_mod('pickup_tag','pickup');
52
+ $pickupposts = get_posts( 'tag='.$pickup_tag );
53
+ ?>
54
+ <?php get_header(); ?>
55
+ <div id="main-wrap">
56
+ <!-- main -->
57
+ <?php $sidebarset = get_post_meta($post->ID, 'single_sidebar_settings', true); ?>
58
+
59
+ <main id="single-main" <?php if(!empty($sidebarset)){ echo 'class="full"'; } ?> style="<?php echo main_position() ?>" role="main">
60
+ <?php (is_active_sidebar( 'single-top-widget' ))?dynamic_sidebar('single-top-widget'):''; ?>
61
+ <?php if(get_theme_mod('catnewpost','top')=="top"&&$pickupposts&&$pickup_tag): ?>
62
+ <?php get_template_part('/lib/parts/pickup','post'); ?>
63
+ <?php endif; ?>
64
+ <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
65
+ <!-- パンくず -->
66
+ <?php echo (get_theme_mod('breadcrumb_set_post',true))?get_template_part('/lib/parts/breadcrumb'):''; ?>
67
+ <div id="content_area" class="fadeIn animated">
68
+ <?php get_template_part('/lib/parts/sns','side') ?>
69
+ <article id="post-<?php the_ID(); ?>" <?php post_class(); ?> <?php if(diver_fix_sns_boolean()): ?> style="margin-<?php echo ($position=='left')?'right':'left'; ?>: 120px"<?php endif; ?>>
70
+ <header>
71
+ <div class="post-meta clearfix">
72
+ <div class="cat-tag">
73
+ <?php
74
+ foreach((get_the_category()) as $cat): ?>
75
+ <div class="single-post-category" style="background:<?php echo get_theme_mod($cat->slug);?>"><a href="<?php echo get_category_link( $cat->cat_ID ) ?>" rel="category tag"><?php echo $cat->cat_name; ?></a></div>
76
+ <?php endforeach; ?>
77
+ <?php
78
+ if(get_theme_mod('post_tag',true)):
79
+ $posttags = get_the_tags();
80
+ if ($posttags) {
81
+ foreach($posttags as $tag) {
82
+ echo '<div class="tag"><a href="'. get_tag_link($tag->term_id) .'" rel="tag">'. $tag->name ."</a></div>";
83
+ }
84
+ }
85
+ endif; ?>
86
+ </div>
87
+
88
+ <h1 class="single-post-title entry-title"><?php echo get_the_title(); ?></h1>
89
+ <div class="post-meta-bottom">
90
+ <?php if(get_theme_mod('single_published_date',true)): ?>
91
+ <time class="single-post-date published updated" datetime="<?php the_time('Y-m-d'); ?>"><i class="fa fa-calendar" aria-hidden="true"></i><?php the_time(get_option( 'date_format' )); ?></time>
92
+ <?php endif; ?>
93
+ <?php if(get_theme_mod('single_modified_date',true)): ?>
94
+ <time class="single-post-date modified" datetime="<?php the_modified_date('Y-m-d'); ?>"><i class="fa fa-refresh" aria-hidden="true"></i><?php the_modified_date(get_option( 'date_format' )) ?></time>
95
+ <?php endif; ?>
96
+ <?php if(get_theme_mod('single_finish_time',false)): ?>
97
+ <span class="post_reading_time">
98
+ <?php
99
+ echo diver_post_reading_time($post->post_content);
100
+ ?>
101
+ </span>
102
+ <?php endif; ?>
103
+
104
+ </div>
105
+ <?php if(get_theme_mod('single_title_author',true)): ?>
106
+ <ul class="post-author vcard author">
107
+ <li class="post-author-thum"><?php echo get_avatar(get_the_author_meta('ID'), 25); ?></li>
108
+ <li class="post-author-name fn post-author"><a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>"><?php the_author(); ?></a>
109
+ </li>
110
+ </ul>
111
+ <?php endif; ?>
112
+ </div>
113
+ <?php
114
+ $paged = (get_query_var('page')) ? get_query_var('page') : 1;
115
+ if($paged==1):
116
+ ?>
117
+
118
+ <?php if(get_option('diver_postsettings_icatch_on',get_theme_mod('single_icatch',1))): ?>
119
+ <?php $eye_img = wp_get_attachment_image_src( get_post_thumbnail_id() , 'medium' ); ?>
120
+ <figure class="single_thumbnail" <?php echo (get_option('diver_postsettings_icatchbg_on',get_theme_mod('single_icatch_bg',1)))?'style="background-image:url('.$eye_img[0].')"':''; ?>>
121
+ <?php echo get_diver_thumb_img('full',false,'',true ,false); ?>
122
+ </figure>
123
+ <?php endif; ?>
124
+
125
+ <?php sharebtn(get_option('diver_sns_post_top_style',get_theme_mod('sharebtn_style_top','big')),'top'); ?>
126
+
127
+ <?php endif; ?>
128
+ </header>
129
+ <section class="single-post-main">
130
+ <?php if(!$adremove):
131
+ dynamic_sidebar('single-top');
132
+
133
+ if(get_option('diver_option_base_ad_posttop') != 4){
134
+ echo diver_option_get_adsence(get_option('diver_option_base_ad_posttop'));
135
+ }else{
136
+ echo do_shortcode(get_option('diver_option_base_ad_posttop_custom'));
137
+ }
138
+ elseif(get_post_meta(get_the_ID(),'single_adarea_top',true)): ?>
139
+ <div class="single-top">
140
+ <?php echo do_shortcode(get_post_meta(get_the_ID(),'single_adarea_top',true)); ?>
141
+ </div>
142
+ <?php endif; ?>
143
+
144
+
145
+ <div class="content">
146
+ <?php if($post->post_password){echo apply_filters('the_content', get_post_meta(get_the_ID(),'auth_before_content',true));} ?>
147
+ <?php the_content(); ?>
148
+ </div>
149
+
150
+ <?php get_template_part('/lib/parts/pager-next-links'); ?>
151
+
152
+ <?php if(!$adremove):
153
+ if(get_option('diver_option_base_ad_postbottom') != 4){
154
+ echo diver_option_get_adsence(get_option('diver_option_base_ad_postbottom'));
155
+ }else{
156
+ echo do_shortcode(get_option('diver_option_base_ad_postbottom_custom'));
157
+ }
158
+ ?>
159
+ <div class="bottom_ad clearfix">
160
+ <?php (is_mobile())?dynamic_sidebar('single-spad'):dynamic_sidebar('single-pcad'); ?>
161
+ </div>
162
+ <?php else:
163
+ if(is_mobile()&&get_post_meta(get_the_ID(),'single_adarea_bottom_sp',true)){ ?>
164
+ <div class="bottom_ad clearfix">
165
+ <?php echo do_shortcode(get_post_meta(get_the_ID(),'single_adarea_bottom_sp',true)); ?>
166
+ </div>
167
+ <?php }
168
+
169
+ if(!is_mobile()&&get_post_meta(get_the_ID(),'single_adarea_bottom_pc',true)){ ?>
170
+ <div class="bottom_ad clearfix">
171
+ <?php echo do_shortcode(get_post_meta(get_the_ID(),'single_adarea_bottom_pc',true)); ?>
172
+ </div>
173
+ <?php }
174
+ endif; ?>
175
+ <?php sharebtn(get_option('diver_sns_post_bottom_style',get_theme_mod('sharebtn_style_bottom','big')),'bottom'); ?>
176
+ <?php get_template_part('/lib/parts/parts','author'); ?>
177
+ </section>
178
+ ```