質問編集履歴
1
回答をいただいたので試した方法を追記します。
test
CHANGED
File without changes
|
test
CHANGED
@@ -99,3 +99,77 @@
|
|
99
99
|
|
100
100
|
|
101
101
|
よろしくお願いいたします。
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
回答をいただいたので試した方法を追記します。
|
108
|
+
|
109
|
+
```PHP
|
110
|
+
|
111
|
+
<?php
|
112
|
+
|
113
|
+
//一覧情報取得
|
114
|
+
|
115
|
+
$result = $anoteher_wpdb->get_results("
|
116
|
+
|
117
|
+
SELECT post_title, id, guid, post_date
|
118
|
+
|
119
|
+
FROM $anoteher_wpdb->posts
|
120
|
+
|
121
|
+
WHERE post_type = 'post'
|
122
|
+
|
123
|
+
AND post_status = 'publish' /* かつ公開済の記事 */
|
124
|
+
|
125
|
+
ORDER BY post_date DESC /* 新しい順に並び替え */
|
126
|
+
|
127
|
+
LIMIT 6
|
128
|
+
|
129
|
+
");
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
$the_post_id = 0;// カテゴリとアイキャッチを取得したい投稿のID
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
$sql_for_categories = "SELECT t.term_id, t.name, t.slug
|
138
|
+
|
139
|
+
FROM {$anoteher_wpdb->term_relationships} AS tr
|
140
|
+
|
141
|
+
INNER JOIN {$anoteher_wpdb->terms} AS t ON t.term_id = tr.term_taxonomy_id
|
142
|
+
|
143
|
+
WHERE tr.object_id = {$the_post_id}";
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
$categories = $anoteher_wpdb->get_results($sql_for_categories, ARRAY_A);
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
$sql_for_eyecatch = "SELECT meta_value
|
152
|
+
|
153
|
+
FROM {$anoteher_wpdb->postmeta}
|
154
|
+
|
155
|
+
WHERE post_id = (SELECT meta_value FROM {$anoteher_wpdb->postmeta} WHERE post_id = {$the_post_id} AND meta_key = '_thumbnail_id') AND meta_key = '_wp_attached_file'";
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
$eyecatch = $anoteher_wpdb->get_var($sql_for_eyecatch);
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
//表示
|
164
|
+
|
165
|
+
foreach ($results as $value) {
|
166
|
+
|
167
|
+
$date = str_replace('-', '.', mb_substr($value->post_date, 0, 10));
|
168
|
+
|
169
|
+
print('<dt><span class="date">'.$date.'</span><span class="cate">'.$categories.'</span></dt><dd><a href="'.$value->guid.'"><img src="'.$value->eyecatch[0].'" />'.$value->post_title.'</a></dd>');
|
170
|
+
|
171
|
+
}
|
172
|
+
|
173
|
+
?>
|
174
|
+
|
175
|
+
```
|