WordPressのthe_contentをthe_excerptを変えようとしたら超大変だったでござるorzの巻
前にちょっとだけ WordPress の一覧ページの表示を抜粋形式にしてたことがあって、そん時は more を使っていたんですが、今回 the excerpt を使って抜粋表示に直そうとしたらエラいはまったんで、その辺のことをメモっとこうと思います。
the_content を the_excerpt に変えたら個別ページも抜粋表示になったでござるorzの巻
とりあえず WordPress テーマの中の index.php で the_content を呼び出してる箇所を the_excerpt に変えたらいーんだろ?とか思って適当にいじくってみたら、個別ページ(ブログとかページとか)も含めて WordPress 全部が抜粋表示になっちゃいました、テヘ☆
the_excerpt が適当に記事の内容判断して抜粋に切り替えてくれるのかと思ったんですが、この関数は単に抜粋表示するだけのもので、どのページを抜粋にするかは自分で制御しないといけないみたいです。
twentyeleven テーマとかだと元から the_excerpt が入ってて適当にやってくれるみたいなんですが、今 sakuratan.biz で使ってる barecity テーマの場合はそういう処理が入ってないので自分で設定しないといけないっぽいです。
で、色々試行錯誤したあげく↓みたいな感じでテーマの index.php を修正しました。
the_content(__('(more...)'));
} else {
the_excerpt();
}
is_singular() は個別ページの時に真になります。
the_content の引数 __(‘(more…)’) は前に more を使って抜粋していたときの名残りですのであんま気にしないでください。
twentyeleven とかですとこの辺は↓みたいな感じになってます。
the_excerpt();
} else {
the_content(__('(more...)'));
}
is_search() は検索結果表示の時だけ真になりますので、twentyeleven ですと検索時以外は全文表示してます。
WordPress の is_ 関数は wp-includes/query.php で定義されていますので、色々試してみたい方はソース見てください。
excerpt_length フィルタを設定しても抜粋表示文字数が変わらないでござるorzの巻
一覧に表示する抜粋の長さは、excerpt_length フィルタで制御できるみたいなんで、テーマの functions.php を↓みたいに変えて400文字に設定しようとしたら全然表示数が変わりませんでした。
return 400;
}
add_filter('excerpt_length', 'new_excerpt_length');
ソース grep して調べた結果、WP Multibyte Patch に excerpt_mblength フィルタというのがあって、excerpt_length > excerpt_mblength になると excerpt_mblength のデフォルト値で切り捨てられているため、設定したフィルタが有効になっていない感じでした。
ちなみに WP Multibyte Patch をインスコした状態の excerpt_length とexcerpt_mblength のデフォルト値は 55 と 110 です。
で、最終的に functions.php は↓のようにしました。
return 400;
}
add_filter('excerpt_length', 'new_excerpt_length');
function new_excerpt_mblength($length) {
return 200;
}
add_filter('excerpt_mblength', 'new_excerpt_mblength');
なお WP Multibyte Patch は独自の設定ファイルがあり、wp-content/plugins/wp-multibyte-patch/wpmp-config-sample.php を wp-contents/wpmp-config.php にコピーして設定を書き込むとそれがデフォルトになるみたいです。
なんか面倒くさそうなので functions.php で直しましたが、そういう方法もあるってことで。
ちなみに今回 the_excerpt に変えたかった理由は、抜粋表示してたときの方が Google からのアクセスが多かったからです。( ゚∀゚)o彡゚SEO!SEO!
実際のところ関係あるのか無いのかよく分かりませんが、5月中頃と比べて10倍ぐらい検索エンジンからの流入が落ちてまして、その対応でサーバ移転したりブログの設定変えたりしてます。3ヵ月後ぐらいには結果が分かると思いますので、その頃にそれっぽい記事書くかもしんないす。
Good respond in return of this difficulty with genuine arguments and explaining everything concerning that.
Quality articles is the important to attract the visitors to
go to see the site, that’s what this website is providing.
Hi, always i used to check web site posts here in the early hours in the morning, for the reason that i love to learn more and more.
My weblog movie tube now
ӏ ǥot tҺis website from
mү buddy աҺⲟ shared with me concerning tҺіs web
page ɑnd noա tһіs time
I am visiting tҺіs site ɑnd reading νery informative posts aat tһіѕ place.
Silahkan Cek halaman wweb Kaami demii mendapatkan Info lebih komplit tentang sewa mobil di lombok murah .
Suwun
I աas recommended tɦis website through my cousin. I am not sսre whefher or not thіs post іs writtеn by him ɑѕ no one eⅼsе
understand ѕuch targeted aƄout myy pгoblem. Yοu’re wonderful!
Thank you!
Jangan lupa untuk Kunjungi sutus Aku buat mendapoat Data lebih lengkap lagi menbgenai pijat panggilan murah .
Terima Kasih
This excellent website truly has all of the information and facts I wanted
about this subject and didn’t know who to ask.
it could make slow all system processes ,one c an understand the difference that the proram and site taking delay to spread out up every time.
But, listen to this, for the SAME DAY, yes, yesterday, I
get this short article from Jim Edwards of named
. It’s also been proven that even a large percent of your offline marketing campaigns
have a tendency to wind up online.
Instagram URL Shortener
[...]just beneath, are a lot of totally not connected web-sites to ours, having said that, they are surely worth going over[...]
esports domains
[...]we like to honor numerous other world wide web internet sites on the internet, even though they aren稚 linked to us, by linking to them. Underneath are some webpages worth checking out[...]
clima en chimalhuacan
[...]we came across a cool web page that you just might get pleasure from. Take a appear when you want[...]
designer dogs
[...]below you値l locate the link to some websites that we feel it is best to visit[...]
french bulldog puppies near me
[...]usually posts some really exciting stuff like this. If you are new to this site[...]
isla mujeres golf cart rental
[...]just beneath, are various totally not connected web-sites to ours, nonetheless, they’re certainly worth going over[...]
micro french bulldog
[...]please pay a visit to the web sites we follow, which includes this one particular, because it represents our picks through the web[...]
houston french bulldogs for sale
[...]always a significant fan of linking to bloggers that I enjoy but don稚 get a good deal of link enjoy from[...]
farlight 84 mod
[...]always a massive fan of linking to bloggers that I really like but do not get lots of link enjoy from[...]
securecheats hwid reset
[...]although internet websites we backlink to beneath are considerably not associated to ours, we feel they may be actually really worth a go via, so possess a look[...]
pubg cheats
[...]The information and facts mentioned inside the post are several of the best obtainable [...]
download halo hacks
[...]always a large fan of linking to bloggers that I love but don稚 get a great deal of link appreciate from[...]
valorant hacks
[...]Every the moment inside a even though we decide on blogs that we read. Listed beneath are the most current sites that we select [...]
mexican candy store
[...]usually posts some pretty interesting stuff like this. If you are new to this site[...]
cuautitlan izcalli clima
[...]check below, are some totally unrelated internet websites to ours, on the other hand, they may be most trustworthy sources that we use[...]
best probiotic for french bulldogs
[...]below you will obtain the link to some web pages that we feel it is best to visit[...]
rent a yacht in cancun
[...]Here are a number of the websites we recommend for our visitors[...]
cheap french bulldog puppies under $500
[...]usually posts some quite fascinating stuff like this. If you池e new to this site[...]
french bulldog blue color
[...]below you値l uncover the link to some websites that we assume you must visit[...]
elizabeth kerr
[...]just beneath, are many absolutely not connected internet sites to ours, nevertheless, they’re surely worth going over[...]
french bulldogs to rescue
[...]although web sites we backlink to beneath are considerably not connected to ours, we feel they are really worth a go by way of, so have a look[...]
sole mare vacanze t-shirt
[...]one of our guests a short while ago advised the following website[...]
늑대닷컴
[...]usually posts some very fascinating stuff like this. If you are new to this site[...]
richest vietnamese in america
[...]check beneath, are some absolutely unrelated web sites to ours, nonetheless, they’re most trustworthy sources that we use[...]
늑대닷컴
[...]Here is an excellent Blog You might Find Exciting that we Encourage You[...]
boston terrier puppies in massachusetts
[...]check below, are some entirely unrelated internet websites to ours, on the other hand, they are most trustworthy sources that we use[...]
dog probiotic
[...]Here is a good Weblog You may Obtain Exciting that we Encourage You[...]