回答編集履歴

1

追記

2017/05/19 13:01

投稿

8-0_nyan5
8-0_nyan5

スコア2352

test CHANGED
@@ -41,3 +41,73 @@
41
41
 
42
42
 
43
43
  参考まで。
44
+
45
+
46
+
47
+ 追記
48
+
49
+ ---
50
+
51
+ ```php
52
+
53
+ <?php
54
+
55
+ /* Get all sticky posts */
56
+
57
+ $sticky = get_option( 'sticky_posts' );
58
+
59
+
60
+
61
+ /* Get the 5 newest stickies (change 5 for a different number) */
62
+
63
+ $sticky = array_slice( $sticky, 0, 5 );
64
+
65
+
66
+
67
+ /* Query sticky posts */
68
+
69
+ $the_query = new WP_Query( array( 'post__in' => $sticky, 'ignore_sticky_posts' => 1, 'post_type' => 'news' ) ); //カスタム投稿を追加
70
+
71
+ // The Loop
72
+
73
+ if ( $the_query->have_posts() ) {
74
+
75
+ // $return .= '<ul>';
76
+
77
+ echo '<ul>'; //functions.phpに書き込まないならechoで
78
+
79
+ while ( $the_query->have_posts() ) {
80
+
81
+ $the_query->the_post();
82
+
83
+ // $return .= '<li><a href="' .get_permalink(). '" title="' . get_the_title() . '">' . get_the_title() . '</a><br />' . get_the_excerpt(). '</li>';
84
+
85
+ echo '<li><a href="' .get_permalink(). '" title="' . get_the_title() . '">' . get_the_title() . '</a><br />' . get_the_excerpt(). '</li>'; //functions.phpに書き込まないならechoで
86
+
87
+ }
88
+
89
+ echo '</ul>'; //閉じ忘れ
90
+
91
+ } else {
92
+
93
+ echo "no posts found";
94
+
95
+ }
96
+
97
+ /* Restore original Post Data */
98
+
99
+ wp_reset_postdata();
100
+
101
+ get_footer(); ?>
102
+
103
+ ```
104
+
105
+ もう一つの方も修正してみました。
106
+
107
+ 紹介されているサイトに書いてあるのは、functions.phpに書くやり方のようです。
108
+
109
+ なので $return を echo に直しました。
110
+
111
+
112
+
113
+ 参考まで。