質問編集履歴
6
こういうイメージで作っています
title
CHANGED
File without changes
|
body
CHANGED
@@ -217,4 +217,27 @@
|
|
217
217
|
|
218
218
|
関係のないテンプレートの表記を削除しました。
|
219
219
|
|
220
|
-
昨日教えていただいたコードでrecent_posts.phpの"http://投稿一覧のURL"において、http://localhost/wordpress/blog/とすると、そのページにしか遷移しないので、それをlocalhost/wordpress/blog/2/やlocalhost/wordpress/blog/3/といった風にphpのコードを埋めてページ遷移させたいです。よろしくお願いします。
|
220
|
+
昨日教えていただいたコードでrecent_posts.phpの"http://投稿一覧のURL"において、http://localhost/wordpress/blog/とすると、そのページにしか遷移しないので、それをlocalhost/wordpress/blog/2/やlocalhost/wordpress/blog/3/といった風にphpのコードを埋めてページ遷移させたいです。よろしくお願いします。
|
221
|
+
|
222
|
+
recent_posts.php
|
223
|
+
```php
|
224
|
+
<?php
|
225
|
+
$args = array(
|
226
|
+
'post_type' => 'post',
|
227
|
+
'posts_per_page' => 5,
|
228
|
+
);
|
229
|
+
$the_query = new WP_Query( $args );
|
230
|
+
if ( $the_query->have_posts() ):
|
231
|
+
while ( $the_query->have_posts() ):
|
232
|
+
$the_query->the_post();
|
233
|
+
$category = get_the_category();
|
234
|
+
$category_link = get_category_link( $category[0]->term_id );
|
235
|
+
?>
|
236
|
+
<?php $p_slug = get_page_uri(get_the_ID()); ?>
|
237
|
+
<p><a href="<?php echo $category_link.'#'.$p_slug; ?>" ><?php the_title(); ?></a></p>
|
238
|
+
<?php
|
239
|
+
endwhile;
|
240
|
+
endif;
|
241
|
+
wp_reset_query();
|
242
|
+
```
|
243
|
+
とやるとリンクさきのidにページ内リンクできました。
|
5
わかりにくい説明だったので修正しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -215,4 +215,6 @@
|
|
215
215
|
});
|
216
216
|
```
|
217
217
|
|
218
|
-
関係のないテンプレートの表記を削除しました。
|
218
|
+
関係のないテンプレートの表記を削除しました。
|
219
|
+
|
220
|
+
昨日教えていただいたコードでrecent_posts.phpの"http://投稿一覧のURL"において、http://localhost/wordpress/blog/とすると、そのページにしか遷移しないので、それをlocalhost/wordpress/blog/2/やlocalhost/wordpress/blog/3/といった風にphpのコードを埋めてページ遷移させたいです。よろしくお願いします。
|
4
いらないテンプレートを削除しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -122,16 +122,7 @@
|
|
122
122
|
</div><!--/sidebar-->
|
123
123
|
```
|
124
124
|
|
125
|
-
footer.php
|
126
|
-
```php
|
127
|
-
<div id="footer" class="container">
|
128
|
-
Copyright 2017<?php if(date("Y")!=2017) echo date("-Y"); ?> All right reserved, gomatan1258
|
129
|
-
</div><!--/footer-->
|
130
|
-
<?php wp_footer(); ?>
|
131
125
|
|
132
|
-
</body>
|
133
|
-
</html>
|
134
|
-
```
|
135
126
|
function.php
|
136
127
|
```php
|
137
128
|
<?php
|
3
修正依頼があったため
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
ワードプレスでわからないことがあります。
|
body
CHANGED
@@ -121,66 +121,7 @@
|
|
121
121
|
<?php dynamic_sidebar(); ?>
|
122
122
|
</div><!--/sidebar-->
|
123
123
|
```
|
124
|
-
header.php
|
125
|
-
```php
|
126
|
-
<!DOCTYPE html>
|
127
|
-
<html lang="ja">
|
128
|
-
<head>
|
129
|
-
<meta charset="UTF-8">
|
130
|
-
<title><?php wp_title('|', true, 'right'); bloginfo('name'); ?></title>
|
131
|
-
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.18.1/build/cssreset/cssreset-min.css">
|
132
|
-
<link rel="stylesheet" type="text/css" href="<?php echo get_stylesheet_uri(); ?>">
|
133
|
-
<?php wp_head(); ?>
|
134
|
-
</head>
|
135
|
-
<body>
|
136
|
-
<?php if(is_front_page()) { if (get_header_image() !='') { ?>
|
137
|
-
<div id="main_image">
|
138
|
-
<img src="<?php header_image(); ?>" alt="" title="" />
|
139
|
-
</div>
|
140
|
-
<?php }; }; ?>
|
141
|
-
<div id="header" class="container">
|
142
|
-
<h1><a href="<?php echo home_url('/'); ?>"><?php bloginfo('name');?></a></h1>
|
143
|
-
<div class="wrapper"><?php wp_nav_menu(); ?></div>
|
144
|
-
</div><!--/header-->
|
145
|
-
```
|
146
|
-
page.php
|
147
|
-
```php
|
148
|
-
<?php get_header(); ?>
|
149
|
-
<div id="main" class="container">
|
150
|
-
<div id="posts">
|
151
124
|
|
152
|
-
<?php if(have_posts()):
|
153
|
-
while(have_posts()):
|
154
|
-
the_post();
|
155
|
-
|
156
|
-
?>
|
157
|
-
<div class="post">
|
158
|
-
<div class="post-header">
|
159
|
-
<h2>
|
160
|
-
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
|
161
|
-
</h2>
|
162
|
-
</div>
|
163
|
-
|
164
|
-
<div class="post-content">
|
165
|
-
<?php the_content(); ?>
|
166
|
-
|
167
|
-
</div>
|
168
|
-
</div>
|
169
|
-
|
170
|
-
<?php endwhile;
|
171
|
-
else:
|
172
|
-
?>
|
173
|
-
|
174
|
-
<p>ページはありません!</p>
|
175
|
-
|
176
|
-
<?php endif;
|
177
|
-
?>
|
178
|
-
|
179
|
-
</div><!--/posts-->
|
180
|
-
<?php get_sidebar(); ?>
|
181
|
-
</div><!--/main -->
|
182
|
-
<?php get_footer(); ?>
|
183
|
-
```
|
184
125
|
footer.php
|
185
126
|
```php
|
186
127
|
<div id="footer" class="container">
|
@@ -248,12 +189,39 @@
|
|
248
189
|
wp_reset_query();
|
249
190
|
?>
|
250
191
|
```
|
192
|
+
カスタムHTMLのウィジェットを追加して以下を書き込む
|
193
|
+
[my_php file="recent_posts"]
|
251
194
|
|
195
|
+
ワードプレスのjavascriptのプラグイン
|
252
|
-
|
196
|
+
```javascript
|
197
|
+
jQuery(function() {
|
198
|
+
jQuery(".menu li").hover(function() {
|
199
|
+
jQuery(this).children('ul').show();
|
200
|
+
}, function() {
|
201
|
+
jQuery(this).children('ul').hide();
|
202
|
+
});//プルダウンメニューが表示されます
|
253
203
|
|
254
|
-
|
204
|
+
var page;
|
255
|
-
サイドバーにあるワードプレスに最初からついているカスタムHTMLのウィジェットです。
|
256
|
-
ショートコードも書き漏れがありました。
|
257
205
|
|
206
|
+
jQuery('.more a').on('click', function(event) {
|
258
|
-
|
207
|
+
//aリンクの動作を停止
|
208
|
+
event.preventDefault();
|
209
|
+
//リンク先URLを取得
|
210
|
+
page = jQuery(this).attr('href');
|
211
|
+
jQuery(this).parent().load(page+' div.post-content p',function(){
|
212
|
+
jQuery(this).parent().children().eq(0).hide();
|
213
|
+
});
|
214
|
+
//続きを読む ajaxでページ遷移せずにsingle.phpの一部が表示される
|
215
|
+
});
|
216
|
+
jQuery('a[href^=#]').click(function(){
|
217
|
+
var speed = 500;
|
218
|
+
var href= jQuery(this).attr("href");
|
219
|
+
var target = jQuery(href == "#" || href == "" ? 'html' : href);
|
259
|
-
|
220
|
+
var position = target.offset().top;
|
221
|
+
jQuery("html, body").animate({scrollTop:position}, speed, "swing");
|
222
|
+
return false;
|
223
|
+
});//ページ内リンクすることができる
|
224
|
+
});
|
225
|
+
```
|
226
|
+
|
227
|
+
関係のないテンプレートの表記を削除しました。
|
2
修正しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -249,4 +249,11 @@
|
|
249
249
|
?>
|
250
250
|
```
|
251
251
|
|
252
|
-
編集しなおしました。
|
252
|
+
編集しなおしました。
|
253
|
+
|
254
|
+
追記です。
|
255
|
+
サイドバーにあるワードプレスに最初からついているカスタムHTMLのウィジェットです。
|
256
|
+
ショートコードも書き漏れがありました。
|
257
|
+
|
258
|
+
カスタムHTMLのウィジェットを追加して以下を書き込む
|
259
|
+
[my_php file="recent_posts"]
|
1
わかりやすく編集しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -2,6 +2,233 @@
|
|
2
2
|
|
3
3
|
調べてもなかなか検索できないので教えてください。
|
4
4
|
|
5
|
+
|
6
|
+
ウィジェットについて、すごくご丁寧に教えていただいたのですが、"http://投稿一覧のURL"の部分で、記事一覧の投稿が表示されるページが複数あったときに、その記事の載っている記事一覧のページにページ遷移させたいのですが、やりかたが分かりませんので教えてください。調べ方が下手でなかなかそのやり方が書いてあるサイトにたどり着けなく、6時間はまっています。
|
7
|
+
|
8
|
+
index.php
|
9
|
+
```php
|
10
|
+
<?php get_header(); ?>
|
11
|
+
<div id="main" class="container">
|
12
|
+
<div id="posts">
|
13
|
+
|
14
|
+
<?php if(have_posts()):
|
15
|
+
while(have_posts()):
|
16
|
+
the_post();
|
17
|
+
|
18
|
+
?>
|
19
|
+
<?php $p_slug = get_page_uri(get_the_ID()); ?>
|
20
|
+
<div id="<?php echo $p_slug ?>"></div>
|
21
|
+
|
22
|
+
<div id="test"></div>
|
23
|
+
<div class="post">
|
24
|
+
<div class="post-header">
|
25
|
+
<h2>
|
26
|
+
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
|
27
|
+
</h2>
|
28
|
+
</div>
|
29
|
+
<div class="post-meta">
|
30
|
+
<?php echo get_the_date(); ?> 【<?php the_category(', ') ?>】
|
31
|
+
</div>
|
32
|
+
<div class="post-content">
|
33
|
+
<div class="post-image">
|
34
|
+
|
35
|
+
<?php if(has_post_thumbnail()): ?>
|
36
|
+
<?php the_post_thumbnail(array(100, 100)); ?>
|
37
|
+
<?php else: ?>
|
38
|
+
<img src="<?php echo get_template_directory_uri(); ?>/images.jpg" width="100" height="100">
|
39
|
+
<?php endif; ?>
|
40
|
+
|
41
|
+
</div>
|
42
|
+
<div class="post-body">
|
43
|
+
<div class="post-body-excerpt">
|
44
|
+
<?php the_content('',false,''); ?>
|
45
|
+
</div>
|
46
|
+
|
47
|
+
<div class="more"><a href="<?php the_permalink(); ?>">続きを読む</a></div>
|
48
|
+
<a href="<?php echo '#'.$p_slug ?>">ここ</a>
|
49
|
+
</div>
|
50
|
+
|
51
|
+
</div>
|
52
|
+
</div>
|
53
|
+
<?php endwhile;
|
54
|
+
else:
|
55
|
+
?>
|
56
|
+
|
57
|
+
<p>記事はありません!</p>
|
58
|
+
|
59
|
+
<?php endif;
|
60
|
+
?>
|
61
|
+
|
62
|
+
<div class="navigation">
|
63
|
+
<div class="prev"><?php previous_posts_link(); ?></div>
|
64
|
+
<div class="next"><?php next_posts_link(); ?></div>
|
65
|
+
</div>
|
66
|
+
</div><!--/posts-->
|
67
|
+
<?php get_sidebar(); ?>
|
68
|
+
</div><!--/main -->
|
69
|
+
<?php get_footer(); ?>
|
70
|
+
```
|
71
|
+
single.php
|
72
|
+
```php
|
73
|
+
<?php get_header(); ?>
|
74
|
+
<div id="main" class="container">
|
75
|
+
<div id="posts">
|
76
|
+
|
77
|
+
<?php if(have_posts()):
|
78
|
+
while(have_posts()):
|
79
|
+
the_post();
|
80
|
+
|
81
|
+
?>
|
82
|
+
<div class="post">
|
83
|
+
<div class="post-header">
|
84
|
+
<h2>
|
85
|
+
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
|
86
|
+
</h2>
|
87
|
+
</div>
|
88
|
+
<div class="post-meta">
|
89
|
+
<?php echo get_the_date(); ?> 【<?php the_category(', ') ?>】
|
90
|
+
</div>
|
91
|
+
<div class="post-content">
|
92
|
+
<p>
|
93
|
+
<?php the_content(); ?>
|
94
|
+
</p>
|
95
|
+
|
96
|
+
</div>
|
97
|
+
</div>
|
98
|
+
|
99
|
+
<div class="navigation">
|
100
|
+
<div class="prev"><?php previous_post_link(); ?></div>
|
101
|
+
<div class="next"><?php next_post_link(); ?></div>
|
102
|
+
</div>
|
103
|
+
|
104
|
+
<?php endwhile;
|
105
|
+
else:
|
106
|
+
?>
|
107
|
+
|
108
|
+
<p>記事はありません!</p>
|
109
|
+
|
110
|
+
<?php endif;
|
111
|
+
?>
|
112
|
+
|
113
|
+
</div><!--/posts-->
|
114
|
+
<?php get_sidebar(); ?>
|
115
|
+
</div><!--/main -->
|
116
|
+
<?php get_footer(); ?>
|
117
|
+
```
|
118
|
+
sidebar.php
|
119
|
+
```php
|
120
|
+
<div id="sidebar">
|
121
|
+
<?php dynamic_sidebar(); ?>
|
122
|
+
</div><!--/sidebar-->
|
123
|
+
```
|
124
|
+
header.php
|
125
|
+
```php
|
126
|
+
<!DOCTYPE html>
|
127
|
+
<html lang="ja">
|
128
|
+
<head>
|
129
|
+
<meta charset="UTF-8">
|
130
|
+
<title><?php wp_title('|', true, 'right'); bloginfo('name'); ?></title>
|
131
|
+
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.18.1/build/cssreset/cssreset-min.css">
|
132
|
+
<link rel="stylesheet" type="text/css" href="<?php echo get_stylesheet_uri(); ?>">
|
133
|
+
<?php wp_head(); ?>
|
134
|
+
</head>
|
135
|
+
<body>
|
136
|
+
<?php if(is_front_page()) { if (get_header_image() !='') { ?>
|
137
|
+
<div id="main_image">
|
138
|
+
<img src="<?php header_image(); ?>" alt="" title="" />
|
139
|
+
</div>
|
140
|
+
<?php }; }; ?>
|
141
|
+
<div id="header" class="container">
|
142
|
+
<h1><a href="<?php echo home_url('/'); ?>"><?php bloginfo('name');?></a></h1>
|
143
|
+
<div class="wrapper"><?php wp_nav_menu(); ?></div>
|
144
|
+
</div><!--/header-->
|
145
|
+
```
|
146
|
+
page.php
|
147
|
+
```php
|
148
|
+
<?php get_header(); ?>
|
149
|
+
<div id="main" class="container">
|
150
|
+
<div id="posts">
|
151
|
+
|
152
|
+
<?php if(have_posts()):
|
153
|
+
while(have_posts()):
|
154
|
+
the_post();
|
155
|
+
|
156
|
+
?>
|
157
|
+
<div class="post">
|
158
|
+
<div class="post-header">
|
159
|
+
<h2>
|
160
|
+
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
|
161
|
+
</h2>
|
162
|
+
</div>
|
163
|
+
|
164
|
+
<div class="post-content">
|
165
|
+
<?php the_content(); ?>
|
166
|
+
|
167
|
+
</div>
|
168
|
+
</div>
|
169
|
+
|
170
|
+
<?php endwhile;
|
171
|
+
else:
|
172
|
+
?>
|
173
|
+
|
174
|
+
<p>ページはありません!</p>
|
175
|
+
|
176
|
+
<?php endif;
|
177
|
+
?>
|
178
|
+
|
179
|
+
</div><!--/posts-->
|
180
|
+
<?php get_sidebar(); ?>
|
181
|
+
</div><!--/main -->
|
182
|
+
<?php get_footer(); ?>
|
183
|
+
```
|
184
|
+
footer.php
|
185
|
+
```php
|
186
|
+
<div id="footer" class="container">
|
187
|
+
Copyright 2017<?php if(date("Y")!=2017) echo date("-Y"); ?> All right reserved, gomatan1258
|
188
|
+
</div><!--/footer-->
|
189
|
+
<?php wp_footer(); ?>
|
190
|
+
|
191
|
+
</body>
|
192
|
+
</html>
|
193
|
+
```
|
194
|
+
function.php
|
195
|
+
```php
|
196
|
+
<?php
|
197
|
+
|
198
|
+
add_theme_support( 'custom-header' );
|
199
|
+
|
200
|
+
add_theme_support('menus');
|
201
|
+
|
202
|
+
register_sidebar(
|
203
|
+
array(
|
204
|
+
before_widget => '<div class="widget">',
|
205
|
+
after_widget => '</div>',
|
206
|
+
before_title => '<h3>',
|
207
|
+
after_title => '</h3>',
|
208
|
+
)
|
209
|
+
);
|
210
|
+
|
211
|
+
add_theme_support('post-thumbnails');
|
212
|
+
|
213
|
+
$cssdir = get_stylesheet_directory_uri();
|
214
|
+
wp_enqueue_script( 'theme-script', $cssdir.'/script.php', array('jquery'));
|
215
|
+
|
216
|
+
// ウィジェットでショートコードを使えるようにする
|
217
|
+
add_filter( 'widget_text', 'do_shortcode' );
|
218
|
+
|
219
|
+
// 任意のPHPファイルをショートコード化して扱えるようにする
|
220
|
+
function php_shortcode( $params = array() ) {
|
221
|
+
extract( shortcode_atts( array(
|
222
|
+
'file' => 'default'
|
223
|
+
), $params ));
|
224
|
+
ob_start();
|
225
|
+
include( get_template_directory() . "/$file.php" );
|
226
|
+
return ob_get_clean();
|
227
|
+
}
|
228
|
+
add_shortcode( 'my_php', 'php_shortcode' );
|
229
|
+
|
230
|
+
?>
|
231
|
+
```
|
5
232
|
recent_posts.php
|
6
233
|
```php
|
7
234
|
<?php
|
@@ -21,20 +248,5 @@
|
|
21
248
|
wp_reset_query();
|
22
249
|
?>
|
23
250
|
```
|
24
|
-
functions.php
|
25
|
-
```php
|
26
|
-
// ウィジェットでショートコードを使えるようにする
|
27
|
-
add_filter( 'widget_text', 'do_shortcode' );
|
28
251
|
|
29
|
-
// 任意のPHPファイルをショートコード化して扱えるようにする
|
30
|
-
function php_shortcode( $params = array() ) {
|
31
|
-
extract( shortcode_atts( array(
|
32
|
-
'file' => 'default'
|
33
|
-
), $params ));
|
34
|
-
|
252
|
+
編集しなおしました。
|
35
|
-
include( get_template_directory() . "/$file.php" );
|
36
|
-
return ob_get_clean();
|
37
|
-
}
|
38
|
-
add_shortcode( 'my_php', 'php_shortcode' );
|
39
|
-
```
|
40
|
-
ウィジェットについて、すごくご丁寧に教えていただいたのですが、"http://投稿一覧のURL"の部分で、記事一覧の投稿が表示されるページが複数あったときに、その記事の載っている記事一覧のページにページ遷移させたいのですが、やりかたが分かりませんので教えてください。調べ方が下手でなかなかそのやり方が書いてあるサイトにたどり着けなく、6時間はまっています。
|