質問するログイン新規登録

質問編集履歴

6

試したことの追加

2017/10/30 08:48

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -96,28 +96,28 @@
96
96
  global $id1;
97
97
  return $id1;
98
98
  }
99
- add_shortcode('hytwin', 'shortcode1');
99
+ add_shortcode('shortcode1', 'shortcode1');
100
100
 
101
101
  htmlurl('$id2', '#id名2');
102
102
  function shortcode2() {
103
103
  global $id2;
104
104
  return $id2;
105
105
  }
106
- add_shortcode('hytwin', 'shortcode2');
106
+ add_shortcode('shortcode2', 'shortcode2');
107
107
 
108
108
  htmlurl('$id3', '#id名3');
109
109
  function shortcode3() {
110
110
  global $id3;
111
111
  return $id3;
112
112
  }
113
- add_shortcode('hytwin', 'shortcode3');
113
+ add_shortcode('shortcode3', 'shortcode3');
114
114
 
115
115
  htmlurl('$id4', '#id名4');
116
116
  function shortcode4() {
117
117
  global $id4;
118
118
  return $id4;
119
119
  }
120
- add_shortcode('hytwin', 'shortcode4');
120
+ add_shortcode('shortcode4', 'shortcode4');
121
121
 
122
122
 
123
123
  ```

5

試したことの追加

2017/10/30 08:48

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -77,7 +77,7 @@
77
77
  $id1 = phpQuery::newDocument($html)->find("#id名1")->text();
78
78
  return $id1;
79
79
  ```
80
- ###やってみたこと
80
+ ###試したこと
81
81
  ```
82
82
  function htmlurl($id, $htmlid) {
83
83
  require_once("phpQuery-onefile.php");

4

追加

2017/10/30 07:14

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -63,8 +63,9 @@
63
63
  add_shortcode('shortcode1', 'shortcode'); id名〜id名4のショートコードを利用したい。
64
64
 
65
65
  ```
66
- ###やってみ
66
+ ###ay03様からいだいた回答の以下部分の処理をまめたい
67
67
  ```
68
+ ```
68
69
  require_once("phpQuery-onefile.php");
69
70
  if(is_page('1')){
70
71
  $html = file_get_contents("URL1");
@@ -73,6 +74,51 @@
73
74
  }else{
74
75
  $html = file_get_contents("URL3");
75
76
  }
76
- $id4 = phpQuery::newDocument($html)->find("#id名4")->text();
77
+ $id1 = phpQuery::newDocument($html)->find("#id名1")->text();
78
+ return $id1;
79
+ ```
80
+ ###やってみたこと
81
+ ```
82
+ function htmlurl($id, $htmlid) {
83
+ require_once("phpQuery-onefile.php");
84
+ if(is_page('1')){
85
+ $html = file_get_contents("URL1");
86
+ }elseif(is_page('2')){
87
+ $html = file_get_contents("URL2");
88
+ }else{
89
+ $html = file_get_contents("3");
90
+ }
91
+ $id = phpQuery::newDocument($html)->find($htmlid)->text();
92
+ return $id;
93
+ }
94
+ htmlurl('$id1', '#id名1');
95
+ function shortcode1() {
96
+ global $id1;
97
+ return $id1;
98
+ }
99
+ add_shortcode('hytwin', 'shortcode1');
100
+
101
+ htmlurl('$id2', '#id名2');
102
+ function shortcode2() {
103
+ global $id2;
104
+ return $id2;
105
+ }
106
+ add_shortcode('hytwin', 'shortcode2');
107
+
108
+ htmlurl('$id3', '#id名3');
109
+ function shortcode3() {
110
+ global $id3;
111
+ return $id3;
112
+ }
113
+ add_shortcode('hytwin', 'shortcode3');
114
+
115
+ htmlurl('$id4', '#id名4');
116
+ function shortcode4() {
117
+ global $id4;
77
- return $id4;
118
+ return $id4;
119
+ }
120
+ add_shortcode('hytwin', 'shortcode4');
121
+
122
+
78
- ```
123
+ ```
124
+ 結果 空白

3

やってみたことの追加

2017/10/30 06:55

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -62,4 +62,17 @@
62
62
  }
63
63
  add_shortcode('shortcode1', 'shortcode'); id名〜id名4のショートコードを利用したい。
64
64
 
65
+ ```
66
+ ###やってみたこと
67
+ ```
68
+ require_once("phpQuery-onefile.php");
69
+ if(is_page('1')){
70
+ $html = file_get_contents("URL1");
71
+ }elseif(is_page('2')){
72
+ $html = file_get_contents("URL2");
73
+ }else{
74
+ $html = file_get_contents("URL3");
75
+ }
76
+ $id4 = phpQuery::newDocument($html)->find("#id名4")->text();
77
+ return $id4;
65
78
  ```

2

```の追加

2017/10/30 06:46

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -15,7 +15,7 @@
15
15
  ショートコードを利用して固定ぺージに表示
16
16
 
17
17
  ※抽出元のHTMLは例とは別でそれぞれ若干違います。
18
-
18
+ ```
19
19
  ###該当のソースコード
20
20
  URL1のサイト
21
21
  <ul>
@@ -46,7 +46,8 @@
46
46
  <li><p id="id名3"></p></li>
47
47
  <li id="id名4"></li>
48
48
  </ul>
49
-
49
+ ```
50
+ ```
50
51
  WordPressのfunction.phpに記載してるもの
51
52
  function shortcode() {
52
53
  require_once("phpQuery-onefile.php");

1

文法の修正

2017/10/26 09:38

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -50,15 +50,15 @@
50
50
  WordPressのfunction.phpに記載してるもの
51
51
  function shortcode() {
52
52
  require_once("phpQuery-onefile.php");
53
- if(is_page('1')){//固定ページ1だった場合は$htmlにURL1のサイトを
53
+ if(is_page('1')){ //固定ページ1だった場合は$htmlにURL1のサイトを
54
54
  $html = file_get_contents("URL1");
55
55
  }elseif(is_page('2')){
56
- $html = file_get_contents("URL2");//固定ページ2だった場合は$htmlにURL2のサイトを
56
+ $html = file_get_contents("URL2"); //固定ページ2だった場合は$htmlにURL2のサイトを
57
57
  }else{
58
- $html = file_get_contents("URL3");その他の場合は$htmlにURL3のサイトを
58
+ $html = file_get_contents("URL3"); //その他の場合は$htmlにURL3のサイトを
59
59
  }
60
60
  return phpQuery::newDocument($html)->find("#id名")->text();
61
61
  }
62
- add_shortcode('shortcode1', 'shortcode');
62
+ add_shortcode('shortcode1', 'shortcode'); id名〜id名4のショートコードを利用したい。
63
63
 
64
64
  ```