Posted: 2011.04.10 / Category: WordPress / Tag: Ajax, jQuery 通常のブログではあまり使うことはないかもしれませんが、jQueryの練習がてらWordpressの続きを読むをAjaxで読み込んでみようと思います。 WordPressのテンプレート 動作はタイトルと概要と「続きを読む」ボタンを記事一覧に表示して、「続きを読む」ボタンを押すと、ボタンが本文に置き換わるということをやります。 まずはテンプレートファイルを普通(?)に作成します。 一覧を表示するための「index.php」と、本文を表示するための「single.php」ですね。 index.php <?php get_header(); ?> <div id="entry"> <?php if (have_posts()) : while (have_posts()) :
投稿ページに任意のボタンを追加する 投稿ページに任意のボタンを追加して、何かのアクションを加えたい。 add_action(‘post_submitbox_misc_actions’, ‘callback_functions’); add_action('post_submitbox_misc_actions', 'callback_functions');のfunctionがあるのでそちらを使って、投稿ページの公開ウィジット部分に新たにボタンを追加します。 get_post_satus() 投稿ページにて、記事のステータスを取得できます。 記事のステータスを取得して、publish以外の時だけ表示するようにします。 add_action( 'post_submitbox_misc_actions', 'check_proofreading_button' ); function ch
選択フォームでオプションを一個一個選んでいくのは、意外と手間がかかります。そこで「全て選択」ボタンを作って、jQueryで一括操作できるようにしてみました。フォームで選択肢が多い場合などに役立ちます。
WordPressを使ってサイト構築するとき、jQueryを使ってカスタマイズすることが多いと思います。 このサイトでもAjax+pushStateなどの技術を使うためにjQueryを多用しています。 WordPressでjQueryを使う じつはWordPressにはjQueryもパッケージされているので、自分のサーバーにjQueryを置いたりGoogleなどのCDNを読みこまなくても、header.phpに<?php wp_head(); ?>と書けば必要に応じて勝手に読み込まれます。 しかし問題があります WordPressにパッケージされているjQueryは、WordPressの独自仕様になっていて、ちょっと使いづらいんです。 具体的には、jQuery.noConflict();という関数が実行されていて(参考記事)、要はjQueryと似たような記法のjQuery以外のJavaSc
この投稿は 11年半 前に公開されました。いまではもう無効になった内容を含んでいるかもしれないことをご了承ください。 最近プラグインカスタマイズやテーマカスタマイズを請け負うことが多いのですが、その過程で気づいたことをば共有します。 WordPressはjQueryを中心にして、たくさんのJavascriptライブラリを採用しています。主に管理画面で使っているもの中心ですが、けっこう沢山あります。 WordPressで使われているJS WordPressでJavascriptを読み込む時はwp_enqueue_scriptを使うと色々よしなにしてもらえるのですが、このリストはCodexのwp_enqueue_scriptの項目に挙がっています。ただ、実際にはもっとたくさんのライブラリが入っていることがわかりました。 これらのスクリプトにはそれぞれ名前が割り当てられていて、依存関係(ex.
CSSやJavaScriptなどの外部ファイルを読み込む際、全ページ共通で且つよく見かける方法だとheader.phpのhead内に記述するということが多いと思いますが、例えば投稿ページでは使うけど固定ページでは必要ないので読み込ませたくない場合があります。 head内で条件分岐させる方法もありますが、それをfunctions.phpを使って一元管理する方法です。 また、その際に追記されてしまうバージョン表記を消す方法も合わせて紹介します。 JavaScriptを管理する 例としてIDがそれぞれ1~3まで設定されている固定ページに、以下の4つのjsを適応させるという想定で説明していきます。 jquery-1.7.2.min.js(全ページに適応) common.js(全ページに適応) slide.js(固定ページ1のみに適応) lightbox.js(固定ページ2と3に適応) 上記のような
2013年3月23日 Wordpress WordPressでコーディング中、「理由はなんだかわかんないけどちゃんと動作してくれない!」なんて事がありませんか?私は度々ありました。その都度ググって解決策を探していたのですが、そのお助けコードメモがEvernoteに結構たまってきたので記事にしてみます。よくわからないけど動かない!という時に試してみてください! ↑私が10年以上利用している会計ソフト! お助けコードを使う前に 今まで動いていたのに突然動かなくなった!そんな時は慌てず、とりあえず以下を確認してみてください。プラグインが原因で動作しなくなる事が多いですね。 有効化しているプラグインをすべて無効化して試す </head> の前に <?php wp_head(); ?> があるか </body> の前に <?php wp_footer(); ?> があるか PHPコード(特にif構文
画像を多用した記事を書いていると、ページを遷移せずに画像を拡大表示させる機能は必須だなぁと強く感じます。 そこでLightboxなどのJavaScriptライブラリを利用するわけですが、WordPressではプラグイン化されたLightbox風ライブラリを導入することで、Lightbox風の機能を簡単に実現することが出来ます。なんて便利なんだWordPress! そんなわけでLightBox風機能を導入すべく、いくつかプラグインを試してみました。 Lightbox風プラグインをいくつか試してみた。 早速WordPressのプラグイン検索で「Lightbox」や「Colorbox」と検索してみましたが、同じライブラリを利用したプラグインがたくさん出てきました。 全部試すか…!いや無理だ…。取り敢えず更新があまり止まっていない人気のありそうなプラグインをいくつか試してみることにします。 今
【img via WordPress Pencil and Pins-07 by thisismyurl】 ブログの表示速度は早ければ早い方が良い! そう思って様々なWordPress用プラグインを試しているのだが、最近、画面内に画像が表示された段階で画像を読み込むような動作をしているメディアが気になっていた。 調べてみたところ、そのような処理をしてくれる「jQuery Image Lazy Load WP」というプラグインがあった。実際に導入してみたらそれなりに効果を発揮したので、紹介する! 「jQuery Image Lazy Load WP」のインストール 「jQuery Image Lazy Load WP」を入れることによってどういう効果があるかというと、本来であればページ内にある全画像を最初に読み込むため特に画像数が多い記事やページは読み込み速度が遅くなりがちなのだが、このプラ
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く