質問編集履歴
2
解決方法コード修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -80,15 +80,23 @@
|
|
80
80
|
|
81
81
|
```ここに言語を入力
|
82
82
|
|
83
|
-
<
|
83
|
+
<?php
|
84
84
|
|
85
|
+
$terms = get_field('author_article_list');
|
86
|
+
|
87
|
+
if( $terms ): ?>
|
88
|
+
|
89
|
+
<ul>
|
90
|
+
|
91
|
+
<?php foreach( $terms as $term ): ?>
|
92
|
+
|
85
|
-
<?php
|
93
|
+
<li><a href="<?php echo get_term_link( $term ); ?>">
|
86
94
|
|
87
95
|
<?php
|
88
96
|
|
89
|
-
$term_sp = get_t
|
97
|
+
$term_sp = get_term_by( 'id', $term, 'articlecat' );
|
90
98
|
|
91
|
-
$term_idsp = 'articlecat_'.$term_
|
99
|
+
$term_idsp = 'articlecat_'.$term_sp->term_id;
|
92
100
|
|
93
101
|
$photo = get_field('cat_images_02',$term_idsp);
|
94
102
|
|
@@ -96,19 +104,17 @@
|
|
96
104
|
|
97
105
|
?>
|
98
106
|
|
99
|
-
<img src="<?php echo $photosp[0]; ?>" alt="<?php echo $term_
|
107
|
+
<img src="<?php echo $photosp[0]; ?>" alt="<?php echo $term_sp->name ?>">
|
100
108
|
|
101
|
-
<
|
109
|
+
</a>
|
102
110
|
|
103
|
-
|
111
|
+
</li>
|
104
112
|
|
105
|
-
|
113
|
+
<?php endforeach; ?>
|
106
114
|
|
107
|
-
|
115
|
+
</ul>
|
108
116
|
|
109
|
-
<img src="<?php echo $icatchimage[0]; ?>" alt="<?php echo get_the_title(get_field('header_images')) ?>" />
|
110
|
-
|
111
|
-
<?php endif;?>
|
117
|
+
<?php endif; ?>
|
112
118
|
|
113
119
|
```
|
114
120
|
|
1
解決方法追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -74,4 +74,42 @@
|
|
74
74
|
|
75
75
|
|
76
76
|
|
77
|
+
##解決したコード
|
78
|
+
|
79
|
+
無事解決しました。やりたいことを色々と織り交ぜすぎてシンプルにできるところをしていなかったため、コードがぐちゃぐちゃになってしまったのが原因かと思います。
|
80
|
+
|
81
|
+
```ここに言語を入力
|
82
|
+
|
83
|
+
<li><a href="<?php echo get_term_link( $term ); ?>"><?php $ctm = get_post_meta($post->ID, 'header_images', true);?>
|
84
|
+
|
85
|
+
<?php if(empty($ctm)):?><!-- // なぜ$post->ID の 'header_images' を基準に分岐しているのかが意味がわからない。$termの画像を出すのが主目的なのでは? -->
|
86
|
+
|
87
|
+
<?php
|
88
|
+
|
89
|
+
$term_sp = get_the_terms( $post->ID, 'articlecat' ); // get_the_termsは当該記事に所属するterm情報を配列で返すのでなぜ使っているかがわからない。$termにidが入っているなら、get_term_by( 'id', $term, 'articlecat' )じゃね?
|
90
|
+
|
91
|
+
$term_idsp = 'articlecat_'.$term_id; // どこから$term_idが出てきたんだろう。100歩譲って「$term_sp[0]->term_id」だろうな、と思う。get_term_byを使った場合「$term_sp->term_id」。
|
92
|
+
|
93
|
+
$photo = get_field('cat_images_02',$term_idsp);
|
94
|
+
|
95
|
+
$photosp = wp_get_attachment_image_src($photo, 'full');
|
96
|
+
|
97
|
+
?>
|
98
|
+
|
99
|
+
<img src="<?php echo $photosp[0]; ?>" alt="<?php echo $term_name; ?>"><!-- // $term_name はどこから来た?get_term_byを使った場合「$term_sp->name」。 -->
|
100
|
+
|
101
|
+
<?php else : ?>
|
102
|
+
|
103
|
+
<?php
|
104
|
+
|
105
|
+
$icatchimage = wp_get_attachment_image_src(get_field('header_images'), 'full');
|
106
|
+
|
107
|
+
?>
|
108
|
+
|
109
|
+
<img src="<?php echo $icatchimage[0]; ?>" alt="<?php echo get_the_title(get_field('header_images')) ?>" />
|
110
|
+
|
111
|
+
<?php endif;?></a></li>
|
112
|
+
|
113
|
+
```
|
114
|
+
|
77
115
|
画像の呼び出し方が悪いのはわかっているものの、うまくいかないのでご教授お願いいたします。
|