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

質問編集履歴

2

書式の改善

2017/01/29 07:42

投稿

alesta
alesta

スコア16

title CHANGED
File without changes
body CHANGED
@@ -3,7 +3,7 @@
3
3
  変更するためにインラインスタイルを除去したいのですが、どこまで修正してよいのかわかりませんでした。
4
4
 
5
5
  ###発生している問題
6
- 画像サイズをfunction.phpやcssで指定しても、インラインスタイルの影響で反映されません。そして、コード内にstyle部分が見つからないのです。
6
+ 画像サイズをcssで指定しても、インラインスタイルの影響で反映されません。そして、ページコード内にstyle部分が見つからないのです。
7
7
 
8
8
  ###該当のソースコード
9
9
  ```php
@@ -17,15 +17,15 @@
17
17
  the_content();
18
18
  } ?>
19
19
  ```
20
-
20
+ こちらはsingle.phpです。
21
21
  ###試したこと
22
- function.phpやcssでclass名を付けてサイズを指定したがインラインスタイルのために反映されない。コードをいじってみたが画像まで消えてしまう。
22
+ cssでclass名を付けてサイズを指定したがインラインスタイルの方が強いために反映されない。ページコードをいじってみたが画像まで消えてしまう。
23
23
  ```php
24
24
  echo '<img src="'.esc_url( $att_image[0] ).'" width="'.intval( $att_image[1] ).'" height="'.intval( $att_image[2] ).'" class="attachment-full-size" alt="'.esc_attr( $att_excerpt ).'" />'."\n";
25
25
  ```
26
- このあたりにwidthやheightが記載されているので、intvalについても調べてみたのですがイマイチわかりませんでした。
26
+ single.phpのこのあたりにwidthやheightが記載されているので、intvalについても調べてみたのですがイマイチわかりませんでした。
27
27
 
28
- ※上記のsingle.phpのコードを変更しても反映されないのでfunction.phpのコードにもサムネイルの情報がありましたので追記しました。
28
+ ※上記のsingle.phpのコードを変更しても反映されないのでfunction.phpにもサムネイルの情報がありましたのでそちらの可能性かと思いコードを追記しました。
29
29
  ###補足情報(言語/FW/ツール等のバージョンなど)
30
30
  より詳細な情報
31
31
  wordpress 4.7.1

1

該当コード情報の追加

2017/01/29 07:42

投稿

alesta
alesta

スコア16

title CHANGED
File without changes
body CHANGED
@@ -24,8 +24,88 @@
24
24
  echo '<img src="'.esc_url( $att_image[0] ).'" width="'.intval( $att_image[1] ).'" height="'.intval( $att_image[2] ).'" class="attachment-full-size" alt="'.esc_attr( $att_excerpt ).'" />'."\n";
25
25
  ```
26
26
  このあたりにwidthやheightが記載されているので、intvalについても調べてみたのですがイマイチわかりませんでした。
27
+
28
+ ※上記のsingle.phpのコードを変更しても反映されないのでfunction.phpのコードにもサムネイルの情報がありましたので追記しました。
27
29
  ###補足情報(言語/FW/ツール等のバージョンなど)
28
30
  より詳細な情報
29
31
  wordpress 4.7.1
30
32
  theme:chocolate
31
- php
33
+ php
34
+
35
+ 以下にfunction.phpのコードを追加します。
36
+ ```php
37
+ // 2.1.1 - post-thumbnails
38
+ add_theme_support( 'post-thumbnails' );
39
+
40
+ // 2.1.1.0 - thumbnail image
41
+ $thumbnail_crop_x = ( ! empty( $options['thumbnail_crop_x'] ) ) ? esc_attr( $options['thumbnail_crop_x'] ) : 'center';
42
+ $thumbnail_crop_y = ( ! empty( $options['thumbnail_crop_y'] ) ) ? esc_attr( $options['thumbnail_crop_y'] ) : 'center';
43
+ set_post_thumbnail_size( 300, 300, array( $thumbnail_crop_x, $thumbnail_crop_y ) );
44
+
45
+ // 2.1.1.1 - Registers a new image size (post_thumbnails, single-post-thumbnail)
46
+ $featured_size_w = ( ! empty( $options['featured_size_w'] ) ) ? absint( $options['featured_size_w'] ) : 700;
47
+ $featured_size_h = ( ! empty( $options['featured_size_h'] ) ) ? absint( $options['featured_size_h'] ) : 350;
48
+ $featured_crop = false;
49
+
50
+ if ( ! empty( $options['featured_crop'] ) ) {
51
+ if ( $options['featured_crop'] == 'crop' ) {
52
+ $featured_crop_x = ( ! empty( $options['featured_crop_x'] ) ) ? esc_attr( $options['featured_crop_x'] ) : 'center';
53
+ $featured_crop_y = ( ! empty( $options['featured_crop_y'] ) ) ? esc_attr( $options['featured_crop_y'] ) : 'center';
54
+ $featured_crop = array( $featured_crop_x, $featured_crop_y );
55
+ } else {
56
+ $featured_crop = false;
57
+ }
58
+ }
59
+
60
+ // 2.1.1.2 - Changed the name to "single-post-thumbnail" from "post_thumbnail"
61
+ add_image_size( 'post_thumbnail', $featured_size_w, $featured_size_h, $featured_crop );
62
+ add_image_size( 'single-post-thumbnail', $featured_size_w, $featured_size_h, $featured_crop );
63
+
64
+ // 2.1.1.3 - Registers a new image size of home page (home-post-thumbnail)
65
+ if ( ! empty( $options['show_featured_home'] ) ) {
66
+ $featured_home_size_w = ( ! empty( $options['featured_home_size_w'] ) ) ? absint( $options['featured_home_size_w'] ) : 700;
67
+ $featured_home_size_h = ( ! empty( $options['featured_home_size_h'] ) ) ? absint( $options['featured_home_size_h'] ) : 350;
68
+ $featured_home_crop = true;
69
+
70
+ if ( ! empty( $options['featured_home_crop'] ) ) {
71
+ if ( $options['featured_home_crop'] == 'crop' ) {
72
+ $featured_home_crop_x = ( ! empty( $options['featured_home_crop_x'] ) ) ? esc_attr( $options['featured_home_crop_x'] ) : 'center';
73
+ $featured_home_crop_y = ( ! empty( $options['featured_home_crop_y'] ) ) ? esc_attr( $options['featured_home_crop_y'] ) : 'center';
74
+ $featured_home_crop = array( $featured_home_crop_x, $featured_home_crop_y );
75
+ } else {
76
+ $featured_home_crop = false;
77
+ }
78
+ }
79
+
80
+ /* ----------------------------------------------
81
+ * 2.1.1 - post-thumbnails
82
+ * Image size square
83
+ * --------------------------------------------*/
84
+
85
+ if ( ! function_exists( 'chocolat_post_thumbnail' ) ) :
86
+ function chocolat_post_thumbnail() {
87
+ $img_size = 300;
88
+ if ( has_post_thumbnail() ) {
89
+ the_post_thumbnail( 'thumbnail', array( 'alt' => the_title_attribute( 'echo=0' ) ) );
90
+ } else {
91
+ global $post;
92
+ $str = $post->post_content;
93
+ $searchPattern = '/<img.*?src=(["\'])(.+?)\1.*?>/i';
94
+ $noimage_url = get_template_directory_uri() .'/img/common/thumbnail.png';
95
+ $img_class = '';
96
+
97
+ if ( preg_match( $searchPattern, $str, $imgurl ) ) {
98
+ $noimage_url = $imgurl[2];
99
+ $img_class = ' no-thumbnail-image';
100
+ } else {
101
+ $options = chocolat_get_option();
102
+ if ( ! empty( $options['no_image_url'] ) ) {
103
+ $noimage_url = $options['no_image_url'];
104
+ }
105
+ }
106
+ echo '<img src="'.esc_url( $noimage_url ).'" class="attachment-thumbnail wp-post-image'.esc_attr( $img_class ).'" alt="'.the_title_attribute( 'echo=0' ).'" width="'.absint( $img_size ).'" height="'.absint( $img_size ).'" />';
107
+ }
108
+ }
109
+ endif;
110
+
111
+ ```