リンク文字列http://~にAタグをつける方法

置換前

(http[^\r\n ]+)

置換後

<a href="\1">\1</a>

Googleマップの左上の表示を消す方法

実際は大きくマップを表示して、overflowで周りを消して小さく表示
物理的に消すわけではなく、見えなくすると言ったほうが正しいです。

<div style="width: 100%; overflow: hidden; height: 300px;">
<iframe
src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d39797.07748547086!2d5.46683904751879!3d51.433965676849986!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x47c6d90575ca5e3d%3A0x55989f5f344b006!2sPrins+Hendrikstraat+5!5e0!3m2!1snl!2snl!4v1392716144537"
width="100%"
height="600"
frameborder="0"
style="border:0; margin-top: -150px;">
</iframe>
</div>

文字サイズ変更ボタン

結構医療系のサイトだと文字サイズの変更ボタンが必要だったりするのでそれの備忘録。

JS

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script src="common/js/jquery.cookie.js"></script>
<script src="common/js/fontsize.js"></script>

fontsize.js

jQuery(function($){
//変数にクッキー名を入れる
var history = $.cookie('fontSize');
//適用する箇所を指定。今回は部分的に#test内のpに
var elm = $('body');
//変数が空ならfontMを、空でなければクッキーに保存しておいたものを適用
if(!history){
elm.addClass('fontS');
$('#fontS').addClass('active');
}else{
elm.addClass(history);
$('#'+history).addClass('active');
}
//ボタンをクリックしたら実行
$('li','.mod_headerbox_size').click(function(){
//activeでないボタンだった場合のみ動作
if(!$(this).hasClass('active')){
//現在activeのついているclassを削除
$('.active').removeClass('active');
//クリックしたボタンをactive
$(this).addClass('active');
//クリックした要素のID名を変数にセット
var setFontSize = this.id;
//クッキーに変数を保存
$.cookie('fontSize', setFontSize);
//一度classを除去して、変数をclassとして追加
elm.removeClass().addClass(setFontSize);
}
});
});

jquery.cookie.js

/**
* Cookie plugin
*
* Copyright (c) 2006 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/

/**
* Create a cookie with the given name and value and other optional parameters.
*
* @example $.cookie('the_cookie', 'the_value');
* @desc Set the value of a cookie.
* @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
* @desc Create a cookie with all available options.
* @example $.cookie('the_cookie', 'the_value');
* @desc Create a session cookie.
* @example $.cookie('the_cookie', null);
* @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
* used when the cookie was set.
*
* @param String name The name of the cookie.
* @param String value The value of the cookie.
* @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
* @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
* If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
* If set to null or omitted, the cookie will be a session cookie and will not be retained
* when the the browser exits.
* @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
* @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
* @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
* require a secure protocol (like HTTPS).
* @type undefined
*
* @name $.cookie
* @cat Plugins/Cookie
* @author Klaus Hartl/klaus.hartl@stilbuero.de
*/

/**
* Get the value of a cookie with the given name.
*
* @example $.cookie('the_cookie');
* @desc Get the value of a cookie.
*
* @param String name The name of the cookie.
* @return The value of the cookie.
* @type String
*
* @name $.cookie
* @cat Plugins/Cookie
* @author Klaus Hartl/klaus.hartl@stilbuero.de
*/
jQuery.cookie = function(name, value, options) {
if (typeof value != 'undefined') { // name and value given, set cookie
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
}
// CAUTION: Needed to parenthesize options.path and options.domain
// in the following expressions, otherwise they evaluate to undefined
// in the packed version for some reason...
var path = options.path ? '; path=' + (options.path) : '';
var domain = options.domain ? '; domain=' + (options.domain) : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
} else { // only name given, get cookie
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
};

HTML

<div class="mod_headerbox_size">
<ul>
<li id="fontS"><span><img width="30" height="60" alt="小さいサイズ" src="common/img/size_s.jpg"></span></li>
<li id="fontM"><span><img width="30" height="60" alt="少し大きいサイズ" src="common/img/size_m.jpg"></span></li>
<li id="fontL"><span><img width="30" height="60" alt="大きいサイズ" src="common/img/size_b.jpg"></span></li>
</ul>
<!--mod_headerbox_size_end--></div>

CSS

/* fontsize
-----------------------------------------*/
.fontS { font-size: 75% }
.fontM { font-size: 85% }
.fontL { font-size: 95% }

/* mod_headerbox_size
-----------------------------------------*/
.mod_headerbox_size {
width: 90px;
position:relative;
overflow:hidden;
}
.mod_headerbox_size ul {
}
.mod_headerbox_size ul li {
float: left;
width:30px;
height: 30px;
overflow: hidden;
}
.mod_headerbox_size ul li span {
display: block;
cursor: pointer;
}
.mod_headerbox_size ul li.active span {
margin-top: -30px;
}
.mod_headerbox_size ul li span:hover{
margin-top:-30px;
}

画像。

これでできるよ

ユーザ新規追加の時に役割が出ない!

マルチサイト化されたサイトにありがちらしい、ユーザ追加画面で役割のプルダウンが出ないってやつ。
これかなり苦戦しました。

こういう状況。(英語版だけど)

これを直すにはphpMyAdminをいじる必要がある。

該当するサイトのoptionsテーブルの「option_name」のカラムに「wp_user_roles」という値があります。
これを「wp_X_user_roles」に変える。

たとえば、「wp_6_options」とか、所謂ID=6のサイトだった場合、「wp_6_user_roles」に変えてあげる、

これで出るようになる。

海外のフォーラムか何かで見つけたんだけど、ホント結局は頼りになるのは世界70億人のみんなでした。

Recent Posts ExtendedとVK Link Target Controllerを併せて使うとき

Recent Posts Extendedはウィジェット上でカテゴリーを指定して投稿を出力出来る便利プラグインです。

VK Link Target Controllerで投稿のリンクを押下したときに別ページ&別タブにするのは、ここでやりました。

ですが、この対処法はRecent Posts Extendedで出力された投稿には効かないのです・・・

ということで、以下。

いじるファイルはこれ。

../wp-content/plugins/recent-posts-widget-extended/includes/functions.php

その中に、以下のような記述があるところがあります。

$html .= '<h3 class="rpwe-title" id="post-'.get_the_ID().'"><a href="' . esc_url( get_permalink() ) . '" title="' . sprintf( esc_attr__( 'Permalink to %s', 'recent-posts-widget-extended' ), the_title_attribute( 'echo=0' ) ) . '" rel="bookmark">' . esc_attr( get_the_title() ) . '</a></h3>';

h3 class=”rpwe-title”とかで検索引っ掛けるとすぐ見つかります。多分一箇所しかないので。

それで、この↓部分を

<h3 class="rpwe-title">

こうする。

<h3 class="rpwe-title" id="post-'.get_the_ID().'">

これで大丈夫だと思います。

<?php the_ID(); ?>

だと、上手く取得できないので、上みたいに書いてください。
何でかはあとで調べておきます。

余談:
本当に何でもかんでも別タブにしたいときはこうする。

$html .= '<h3 class="rpwe-title"><a href="' . esc_url( get_permalink() ) . '" title="' . sprintf( esc_attr__( 'Permalink to %s', 'recent-posts-widget-extended' ), the_title_attribute( 'echo=0' ) ) . '" target="_blank" rel="bookmark">' . esc_attr( get_the_title() ) . '</a></h3>';

VK Link Target Controllerのリンクを別タブで出す

VK Link Target Controllerという、個別の投稿のリンクを押下すると投稿詳細ではなく別のページにジャンプ出来るプラグインがあります。

それがどうやら、普通のテーマだと別タブで開かないらしいです。外部リンクにしたいとき面倒。
公式テーマ(Twentyシリーズ)とかはいけるっぽいけど・・

ということで以下の対処。

<?php while (have_posts()): the_post(); ?>
<div class="entry">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<span><?php the_excerpt(); ?></span>
</div>
<?php endwhile; ?>

こういう場合、リンクの親要素に以下のid属性を付与。

<div class="entry" id="post-<?php the_ID(); ?>">

おわり。

カテゴリーを一つだけ取得する

使い勝手としては以下。

個別記事をページングしたい。記事のカテゴリは一つだけど、レパートリとして複数カテゴリある。
今のところ単一カテゴリを絞ったページングは可能だけど、複数カテゴリを跨いではしんどい。

結局ページング用カテゴリをページングさせたい記事に設定するしかない・・・

要はこういうこと。
カテゴリー1、2、3を一グループとしてページングさせたい。

記事A>カテゴリ:1
記事B>カテゴリ:2
記事C>カテゴリ:3
記事D>カテゴリ:1

ページング機能で引数をtrueにしてると同一カテゴリでページングすることがアダとなり。記事Aで次へを押すと、本当は記事Bに飛んで欲しいところ記事Dに飛んでしまう。

ということで、以下の対応。

記事A>カテゴリ:1、4
記事B>カテゴリ:2、4
記事C>カテゴリ:3、4
記事D>カテゴリ:1、4

カテゴリ4をページング用として設定。

そうすると、カテゴリ4が共通ということで遷移する・・・けど、記事一覧に表に出てほしくないページング制御用のカテゴリが出てしまう。
ということで、1,2、3などフロント用のカテゴリだけを出すために先頭の一つだけ出力!

先頭の一つだけカテゴリ出力(リンク無し)

<?php
$category = get_the_category();
echo $category[0]->cat_name;
?>

先頭の一つだけカテゴリ出力(リンク有り)

<?php
$category = get_the_category();
if ( $category[0] ) {
echo '<a href="' . get_category_link( $category[0]->term_id ) . '">' . $category[0]->cat_name . '</a>';
}
?>

先頭の二つだけ出力・・・とかになったときはまたその時調べます。

archive.phpなどループ処理で記事の表示件数やカテゴリーを指定する方法

archive.phpとかいじるとうまくいかないことっていっぱいあったけど何かうまくいきました。

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
<div class="post"><?php the_content(); ?></div>
<?php endwhile; ?>
<?php else: ?>
<h2>記事がありません</h2>
<?php endif; ?>

上のループ処理は、記事があればタイトルをタグで、本文を「post」というクラス名の付いたタグで括った状態で表示し、この処理を記事がある分だけ繰り返して行ってください、そして記事がなければ「記事がありません」という文字列をタグで括って表示してください、という意味です。
このループ処理の開始タグの前に1行追加し「どんな記事を探してくるか」などの条件を付加してやることで、表示件数を指定したり、特定のカテゴリーのみを抽出して一覧表示できるようになります。

カテゴリーIDが1,3,5の記事を10個表示する
これがわかればあとは応用

<?php query_posts('cat=1,3,5&posts_per_page=10'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

除外系も。

カテゴリーIDが1,3,5以外の記事を10個表示する

<?php query_posts('cat=-1,-3,-5&posts_per_page=10'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

一つのパーツに複数のウィジェットを入れる

サイドバーで使ってるウィジェットとフッターで使ってるウィジェットを共通化したい時は滅多にないと思う。
けど、要するにそういうことをしたいとき(謎

<!-- ウィジェット1 -->
<?php if(!function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar1')): ?>
<p>ウィジェットが設定されていない場合、ここが表示されます。</p>
<?php endif; ?>
<!-- ウィジェット2 -->
<?php if(!function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar2')): ?>
<p>ウィジェットが設定されていない場合、ここが表示されます。</p>
<?php endif; ?>

正直なところ、sidebar.phpを2つも3つも作ったとき、上半分はサイドバー毎に違うけど、下半分は同じなんだよなってときに使います。
同じウィジェットパーツ沢山つくるのも面倒ですので₍₍ ◝(‘ω’◝) ⁾⁾ ₍₍ (◟’ω’)◟ ⁾⁾

投稿ページの「次へ>」と「<前へ」の自動リンクを同一カテゴリ内の遷移にしたい

正直、prevとnext機能の書き方はテーマ毎に千差万別です。
なので、とりあえず以下の箇所にtrueを入れておけば良いんじゃないかなって感じです。
ふわっとしてますが自分はなんとか上手く行ったのでメモです。

get_previous_post( true );

大体こういうのは「single.php」とか、凝ってるテーマだと「part-single.php」みたいなのに書いてあります。
trueっていうので同一カテゴリーのリンクを取得するみたいですね。
便利。