質問編集履歴
7
コードを変えた
title
CHANGED
File without changes
|
body
CHANGED
@@ -99,26 +99,40 @@
|
|
99
99
|
</div>
|
100
100
|
</div>
|
101
101
|
<div class="link">
|
102
|
+
$paged = ( get_query_var( 'page' ) ) ? get_query_var( 'page' ) : 1;
|
103
|
+
// サブループ条件
|
104
|
+
$args = array(
|
105
|
+
'post_type' => 'post', // 投稿
|
106
|
+
'posts_per_page' => 3, // 表示件数
|
107
|
+
'category_name' => 'blog,news', // カテゴリ// ページ番号
|
108
|
+
);
|
109
|
+
// サブループ情報を取得して「$the_query」変数に代入
|
110
|
+
$the_query = new WP_Query($args);
|
111
|
+
?>
|
112
|
+
<?php /***** サブループ開始 *****/ ?>
|
102
|
-
<?php if (
|
113
|
+
<?php if ($the_query->have_posts()) : ?>
|
114
|
+
<?php while ($the_query->have_posts()) : ?>
|
115
|
+
<?php $the_query->the_post(); ?>
|
116
|
+
|
117
|
+
<?php /**** ▼1件分の投稿内容HTML ****/ ?>
|
118
|
+
<div class="box">
|
119
|
+
<a href="<?php the_permalink(); ?>">
|
120
|
+
<div class="item-title"><?php the_title(); ?></div>
|
121
|
+
</a>
|
122
|
+
</div><!-- .box -->
|
123
|
+
<?php /**** ▲1件分の投稿内容HTML ****/ ?>
|
124
|
+
|
125
|
+
<?php endwhile; ?>
|
126
|
+
<?php endif; ?>
|
103
|
-
|
127
|
+
<?php wp_reset_postdata(); ?>
|
128
|
+
|
129
|
+
<?php /***** サブループ終了 *****/ ?>
|
104
|
-
|
130
|
+
<?php // ページネーション ?>
|
105
|
-
'post_type' => 'blog',
|
106
|
-
'category_name' => 'blog,news',
|
107
|
-
) ); ?>
|
108
131
|
<?php
|
109
|
-
$the_query = new WP_Query( $args );
|
110
|
-
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) :
|
111
|
-
$the_query->the_post(); ?>
|
112
|
-
<?php the_title(); ?></a>
|
113
|
-
<?php endwhile; ?>
|
114
|
-
<?php endif; ?>
|
115
|
-
|
132
|
+
if ( subPagination() ) {
|
116
|
-
<div class="nav-previous alignleft"><?php next_posts_link( '過去の投稿' ); ?></div>
|
117
|
-
<div class="nav-next alignright"><?php previous_posts_link( '新しい投稿' ); ?></div>
|
118
|
-
|
119
|
-
|
133
|
+
echo subPagination();
|
120
|
-
|
134
|
+
}
|
121
|
-
|
135
|
+
?>
|
122
136
|
</div>
|
123
137
|
コード
|
124
138
|
```
|
@@ -134,5 +148,36 @@
|
|
134
148
|
}
|
135
149
|
}
|
136
150
|
add_action( 'pre_get_posts', 'change_posts_per_page' );
|
151
|
+
|
152
|
+
function subPagination($end_size = 1, $mid_size = 2, $prev_next = true) {
|
153
|
+
global $the_query;
|
154
|
+
|
155
|
+
$page_format = paginate_links(
|
156
|
+
array(
|
157
|
+
'current' => max(1, get_query_var('page')),
|
158
|
+
'total' => $the_query->max_num_pages,
|
159
|
+
'type' => 'array',
|
160
|
+
'prev_text' => '前へ',//前へのリンク文言
|
161
|
+
'next_text' => '次へ',//次へのリンク文言
|
162
|
+
'end_size' => $end_size,//初期値:1 両端のページリンクの数
|
163
|
+
'mid_size' => $mid_size,//初期値:2 現在のページの両端にいくつページリンクを表示するか(現在のページは含まない)
|
164
|
+
'prev_next' => $prev_next,//初期値:true リストの中に「前へ」「次へ」のリンクを含むか
|
165
|
+
)
|
166
|
+
);
|
167
|
+
$code = '';
|
168
|
+
if( is_array($page_format) ) {
|
169
|
+
$paged = get_query_var('page') == 0 ? 1 : get_query_var('page');
|
170
|
+
$code .= '<div class="pagination">'.PHP_EOL;
|
171
|
+
$code .= '<ul>'.PHP_EOL;
|
172
|
+
foreach ( $page_format as $page ) {
|
173
|
+
$code .= '<li>'.$page.'</li>'.PHP_EOL;
|
174
|
+
}
|
175
|
+
$code .= '</ul>'.PHP_EOL;
|
176
|
+
$code .= '</div>'.PHP_EOL;
|
177
|
+
$code .= '<div class="pagination-total">'.$paged.'/'.$the_query->max_num_pages.'</div>'.PHP_EOL;
|
178
|
+
}
|
179
|
+
wp_reset_query();
|
180
|
+
return $code;
|
181
|
+
}
|
137
182
|
コード
|
138
183
|
```
|
6
コードを変えた
title
CHANGED
File without changes
|
body
CHANGED
@@ -102,27 +102,23 @@
|
|
102
102
|
<?php if ( have_posts() ) : ?>
|
103
103
|
<?php the_posts_pagination( $args ); ?>
|
104
104
|
<?php the_posts_pagination( array(
|
105
|
-
'
|
105
|
+
'post_type' => 'blog',
|
106
|
-
'
|
106
|
+
'category_name' => 'blog,news',
|
107
|
-
'next_text' => __( 'Onward', 'textdomain' ),
|
108
107
|
) ); ?>
|
109
108
|
<?php
|
110
|
-
$args = array(
|
111
|
-
'post_type' => 'blog',
|
112
|
-
'category_name' => 'blog',
|
113
|
-
'posts_per_page' => 3,
|
114
|
-
);
|
115
109
|
$the_query = new WP_Query( $args );
|
116
110
|
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) :
|
117
111
|
$the_query->the_post(); ?>
|
112
|
+
<?php the_title(); ?></a>
|
118
113
|
<?php endwhile; ?>
|
119
114
|
<?php endif; ?>
|
120
115
|
<?php the_posts_pagination( $args ); ?>
|
121
|
-
<div class="nav-previous alignleft"><?php next_posts_link( '過去の投稿' ); ?></div>
|
116
|
+
<div class="nav-previous alignleft"><?php next_posts_link( '過去の投稿' ); ?></div>
|
122
117
|
<div class="nav-next alignright"><?php previous_posts_link( '新しい投稿' ); ?></div>
|
118
|
+
|
123
119
|
<?php else : ?>
|
124
120
|
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
|
125
|
-
<?php endif; ?>
|
121
|
+
<?php endif; ?>
|
126
122
|
</div>
|
127
123
|
コード
|
128
124
|
```
|
5
コードを変えた
title
CHANGED
File without changes
|
body
CHANGED
@@ -99,35 +99,30 @@
|
|
99
99
|
</div>
|
100
100
|
</div>
|
101
101
|
<div class="link">
|
102
|
-
|
102
|
+
<?php if ( have_posts() ) : ?>
|
103
|
+
<?php the_posts_pagination( $args ); ?>
|
104
|
+
<?php the_posts_pagination( array(
|
105
|
+
'mid_size' => 2,
|
106
|
+
'prev_text' => __( 'Back', 'textdomain' ),
|
103
|
-
|
107
|
+
'next_text' => __( 'Onward', 'textdomain' ),
|
104
|
-
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 6;
|
105
|
-
|
106
|
-
// クエリ
|
107
|
-
$the_query = new WP_Query($args);
|
108
|
-
?>
|
108
|
+
) ); ?>
|
109
109
|
<?php
|
110
|
-
|
110
|
+
$args = array(
|
111
|
-
'post_type' => '
|
111
|
+
'post_type' => 'blog',
|
112
|
-
'category_name' => '
|
112
|
+
'category_name' => 'blog',
|
113
|
+
'posts_per_page' => 3,
|
113
|
-
|
114
|
+
);
|
114
|
-
|
115
|
+
$the_query = new WP_Query( $args );
|
115
|
-
|
116
|
+
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) :
|
116
|
-
|
117
|
+
$the_query->the_post(); ?>
|
117
|
-
<?php the_title(); ?>
|
118
|
-
<?php endwhile; ?>
|
118
|
+
<?php endwhile; ?>
|
119
|
-
<?php
|
120
|
-
// next_posts_link() に max_num_pages を指定して使う
|
121
|
-
next_posts_link( 'Older Entries', $the_query->max_num_pages );
|
122
|
-
previous_posts_link( 'Newer Entries' );
|
123
|
-
?>
|
124
|
-
<?php
|
125
|
-
// クエリとページネーションをクリーンアップ(メインクエリを再設定)
|
126
|
-
wp_reset_postdata();
|
127
|
-
?>
|
128
|
-
<?php else: ?>
|
129
|
-
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
|
130
|
-
<?php endif; ?>
|
119
|
+
<?php endif; ?>
|
120
|
+
<?php the_posts_pagination( $args ); ?>
|
121
|
+
<div class="nav-previous alignleft"><?php next_posts_link( '過去の投稿' ); ?></div>
|
122
|
+
<div class="nav-next alignright"><?php previous_posts_link( '新しい投稿' ); ?></div>
|
123
|
+
<?php else : ?>
|
124
|
+
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
|
125
|
+
<?php endif; ?>
|
131
126
|
</div>
|
132
127
|
コード
|
133
128
|
```
|
4
コードを変えた
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
前後の記事一覧へのリンクを表示するプログラムを組んだんですがうまく機能しません。リンクの画像の部分を押しても投稿が変わりません。カスタム投稿タイプは混ぜています。1つめはfront-page.phpを使っており、2つめはfunction.phpです。
|
2
2
|
コードを変えたんですけど機能しません。Older Entriesと,Newer Entriesというリンクのついた文字が出るだけです。
|
3
|
-
|
3
|
+

|
4
|
+
コードを変更したらこの画面が出てきます。
|
4
5
|
```php
|
5
6
|
<div id="main-home">
|
6
7
|
<div class="home-slido">
|
@@ -99,6 +100,13 @@
|
|
99
100
|
</div>
|
100
101
|
<div class="link">
|
101
102
|
<?php
|
103
|
+
// "paged" パラメータを決定(静的フロントページ内のクエリなら 'page' を使う)
|
104
|
+
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 6;
|
105
|
+
|
106
|
+
// クエリ
|
107
|
+
$the_query = new WP_Query($args);
|
108
|
+
?>
|
109
|
+
<?php
|
102
110
|
$args = array(
|
103
111
|
'post_type' => 'post',
|
104
112
|
'category_name' => 'news,blog',
|
@@ -113,6 +121,10 @@
|
|
113
121
|
next_posts_link( 'Older Entries', $the_query->max_num_pages );
|
114
122
|
previous_posts_link( 'Newer Entries' );
|
115
123
|
?>
|
124
|
+
<?php
|
125
|
+
// クエリとページネーションをクリーンアップ(メインクエリを再設定)
|
126
|
+
wp_reset_postdata();
|
127
|
+
?>
|
116
128
|
<?php else: ?>
|
117
129
|
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
|
118
130
|
<?php endif; ?>
|
3
コードを書きクエ会えた
title
CHANGED
File without changes
|
body
CHANGED
@@ -99,35 +99,20 @@
|
|
99
99
|
</div>
|
100
100
|
<div class="link">
|
101
101
|
<?php
|
102
|
-
// "paged" パラメータを決定(静的フロントページ内のクエリなら 'page' を使う)
|
103
|
-
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
|
104
|
-
|
105
|
-
// クエリ
|
106
|
-
$the_query = new WP_Query( 'cat=1&paged=' . $paged );
|
107
|
-
?>
|
108
|
-
|
109
|
-
|
110
|
-
<?php
|
111
102
|
$args = array(
|
112
103
|
'post_type' => 'post',
|
113
104
|
'category_name' => 'news,blog',
|
114
|
-
|
105
|
+
);
|
115
|
-
|
106
|
+
$the_query = new WP_Query( $args );
|
116
|
-
|
107
|
+
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) :
|
117
|
-
|
108
|
+
$the_query->the_post(); ?>
|
109
|
+
<?php the_title(); ?>
|
118
110
|
<?php endwhile; ?>
|
119
|
-
|
120
111
|
<?php
|
121
112
|
// next_posts_link() に max_num_pages を指定して使う
|
122
|
-
next_posts_link( 'Older Entries', $the_query->max_num_pages);
|
113
|
+
next_posts_link( 'Older Entries', $the_query->max_num_pages );
|
123
114
|
previous_posts_link( 'Newer Entries' );
|
124
115
|
?>
|
125
|
-
|
126
|
-
<?php
|
127
|
-
// クエリとページネーションをクリーンアップ(メインクエリを再設定)
|
128
|
-
wp_reset_postdata();
|
129
|
-
?>
|
130
|
-
|
131
116
|
<?php else: ?>
|
132
117
|
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
|
133
118
|
<?php endif; ?>
|
2
コードを変えた
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
前後の記事一覧へのリンクを表示するプログラムを組んだんですがうまく機能しません。リンクの画像の部分を押しても投稿が変わりません。カスタム投稿タイプは混ぜています。1つめはfront-page.phpを使っており、2つめはfunction.
|
1
|
+
前後の記事一覧へのリンクを表示するプログラムを組んだんですがうまく機能しません。リンクの画像の部分を押しても投稿が変わりません。カスタム投稿タイプは混ぜています。1つめはfront-page.phpを使っており、2つめはfunction.phpです。
|
2
|
+
コードを変えたんですけど機能しません。Older Entriesと,Newer Entriesというリンクのついた文字が出るだけです。
|
2
3
|
|
3
4
|
```php
|
4
5
|
<div id="main-home">
|
@@ -97,13 +98,39 @@
|
|
97
98
|
</div>
|
98
99
|
</div>
|
99
100
|
<div class="link">
|
101
|
+
<?php
|
102
|
+
// "paged" パラメータを決定(静的フロントページ内のクエリなら 'page' を使う)
|
103
|
+
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
|
104
|
+
|
105
|
+
// クエリ
|
106
|
+
$the_query = new WP_Query( 'cat=1&paged=' . $paged );
|
107
|
+
?>
|
108
|
+
|
109
|
+
|
110
|
+
<?php
|
111
|
+
$args = array(
|
112
|
+
'post_type' => 'post',
|
113
|
+
'category_name' => 'news,blog',
|
114
|
+
);
|
115
|
+
$the_query = new WP_Query( $args );
|
116
|
+
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) :
|
100
|
-
|
117
|
+
$the_query->the_post(); ?>
|
118
|
+
<?php endwhile; ?>
|
119
|
+
|
120
|
+
<?php
|
121
|
+
// next_posts_link() に max_num_pages を指定して使う
|
122
|
+
next_posts_link( 'Older Entries', $the_query->max_num_pages);
|
123
|
+
previous_posts_link( 'Newer Entries' );
|
124
|
+
?>
|
125
|
+
|
126
|
+
<?php
|
127
|
+
// クエリとページネーションをクリーンアップ(メインクエリを再設定)
|
128
|
+
wp_reset_postdata();
|
129
|
+
?>
|
130
|
+
|
131
|
+
<?php else: ?>
|
101
|
-
|
132
|
+
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
|
102
|
-
|
133
|
+
<?php endif; ?>
|
103
|
-
<div class="previous-link">
|
104
|
-
<?php next_posts_link('<img src="'. get_theme_file_uri('/img/競技-2.png'). '" alt=""'); ?>
|
105
|
-
</div>
|
106
|
-
</a>
|
107
134
|
</div>
|
108
135
|
コード
|
109
136
|
```
|
1
コードを追加した
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,6 +1,101 @@
|
|
1
1
|
前後の記事一覧へのリンクを表示するプログラムを組んだんですがうまく機能しません。リンクの画像の部分を押しても投稿が変わりません。カスタム投稿タイプは混ぜています。1つめはfront-page.phpを使っており、2つめはfunction.phです。
|
2
2
|
|
3
3
|
```php
|
4
|
+
<div id="main-home">
|
5
|
+
<div class="home-slido">
|
6
|
+
<?php
|
7
|
+
$args = array(
|
8
|
+
'post_type' => 'post',
|
9
|
+
'category_name' => 'スライド',
|
10
|
+
);
|
11
|
+
$the_query = new WP_Query( $args );
|
12
|
+
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) :
|
13
|
+
$the_query->the_post(); ?>
|
14
|
+
<div class="home-content">
|
15
|
+
<?php the_content(); ?>
|
16
|
+
<?php endwhile; ?>
|
17
|
+
<?php endif; ?>
|
18
|
+
<?php wp_reset_postdata(); ?>
|
19
|
+
</div>
|
20
|
+
</div>
|
21
|
+
<div id="NEWS">
|
22
|
+
<div class="NEWS-title">
|
23
|
+
<h1>news</h1>
|
24
|
+
</div>
|
25
|
+
<div class="tab-wrap">
|
26
|
+
<div class="tab-group">
|
27
|
+
<div class="tab is-active">全て</div>
|
28
|
+
<div class="tab">お知らせ</div>
|
29
|
+
<div class="tab">ブログ</div>
|
30
|
+
</div>
|
31
|
+
</div>
|
32
|
+
<div class="panel-group">
|
33
|
+
<div class="panel is-show">
|
34
|
+
<?php
|
35
|
+
$args = array(
|
36
|
+
'post_type' => 'post',
|
37
|
+
'category_name' => 'news,blog',
|
38
|
+
);
|
39
|
+
$the_query = new WP_Query( $args );
|
40
|
+
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) :
|
41
|
+
$the_query->the_post(); ?>
|
42
|
+
<div class="left-post-date">
|
43
|
+
<?php echo get_the_date(); ?>
|
44
|
+
</div>
|
45
|
+
<div class="left-post-item">
|
46
|
+
<?php the_category(); ?>
|
47
|
+
</div>
|
48
|
+
<a href="<?php the_permalink(); ?>" class="left-post-title">
|
49
|
+
<?php echo get_the_title(); ?></a>
|
50
|
+
<?php endwhile; ?>
|
51
|
+
<?php endif; ?>
|
52
|
+
<?php wp_reset_postdata(); ?>
|
53
|
+
</div>
|
54
|
+
<div class="panel">
|
55
|
+
<?php
|
56
|
+
$args = array(
|
57
|
+
'post_type' => 'news',
|
58
|
+
'category_name' => 'news',
|
59
|
+
);
|
60
|
+
$the_query = new WP_Query( $args );
|
61
|
+
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) :
|
62
|
+
$the_query->the_post(); ?>
|
63
|
+
<div class="center-news-date">
|
64
|
+
<?php echo get_the_date(); ?>
|
65
|
+
</div>
|
66
|
+
<div class="center-news-item">
|
67
|
+
<?php the_category(); ?>
|
68
|
+
</div>
|
69
|
+
<a href="<?php the_permalink(); ?>" class="center-news-title">
|
70
|
+
<?php the_title(); ?></a>
|
71
|
+
<?php endwhile; ?>
|
72
|
+
<?php endif; ?>
|
73
|
+
<?php wp_reset_postdata(); ?>
|
74
|
+
</div>
|
75
|
+
<div class="panel">
|
76
|
+
<?php
|
77
|
+
$args = array(
|
78
|
+
'post_type' => 'blog',
|
79
|
+
'category_name' => 'blog',
|
80
|
+
);
|
81
|
+
$the_query = new WP_Query( $args );
|
82
|
+
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) :
|
83
|
+
$the_query->the_post(); ?>
|
84
|
+
<div class="left-news-date">
|
85
|
+
<?php echo get_the_date(); ?>
|
86
|
+
</div>
|
87
|
+
<div class="left-news-item">
|
88
|
+
<?php the_category(); ?>
|
89
|
+
</div>
|
90
|
+
<a href="<?php the_permalink(); ?>" class="left-news-title">
|
91
|
+
<?php the_title(); ?></a>
|
92
|
+
<?php endwhile; ?>
|
93
|
+
<?php endif; ?>
|
94
|
+
<?php wp_reset_postdata(); ?>
|
95
|
+
</div>
|
96
|
+
</div>
|
97
|
+
</div>
|
98
|
+
</div>
|
4
99
|
<div class="link">
|
5
100
|
<div class="next-link">
|
6
101
|
<?php previous_posts_link('<img src="'. get_theme_file_uri('/img/競技.png'). '" alt=""'); ?>
|