Wordpress開発メモ
  • Home
  • サンプルページ
  • img

    Responsive WP theme

    We are a group of passionate designers and developers who really love creating awesome WordPress themes & giving support.

    Read More

Busiprof: the perfect WordPress theme for an app and web developer

Awesome Services

We are a group of passionate designers and developers who really love creating awesome WordPress themes & giving support.

Web Design

It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.

Unique Elements

It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.

User Friendly

It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.

24/7 Support

It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.

More Services

Recent Projects

We are a group of passionate designers and developers who really love creating awesome WordPress themes & giving support.

Business cards

Graphic design & web design

Business cards

Graphic design & web design

Business cards

Graphic design & web design

Business cards

Graphic design & web design

Recent Blog

We are a group of passionate designers & developers

1月 16,2019 Leave a Reply wordpress, メール送信, お問い合わせフォーム, Contact Form7, SMTP

WordPressのお問い合わせフォームやメール送信について

問題
WordPressでは、デフォルト/usr/sbin/sendmailコマンドを使用してメールを送信しています。

認証してから送信されるわけではありませんので、
1)迷惑メールになってしまう(迷惑メールフォルダに入ってしまう)ことがある
2)レンタルサーバーによって、送信されないことがある
 例:さくらインターネットのレンタルサーバの場合、sendmailコマンドでは送信できません。
  エラーログ例:malformed header from script ‘index.php’: Bad header: /home/hoge/dead.letter… Sav, referer: http://www.hoge.com/wp/contact-us/

解決策:
WP Mail SMTP プラグインを利用し、SMTPを使って送信します。

WP Mail SMTP プラグインのインストール方法について、ここでは説明を割愛します。

WP Mail SMTP をインストール&有効にし、
設定>WP Mail SMTP よりSMTP設定を行ったあと、
WordPressのメール送信送信がSMTPに経由することになります。

◆参考資料
Contact Form 7で迷惑メールになってしまう問題をWP Mail SMTPで解決

  • Facebook
  • twitter
  • Hatena
  • Pocket

1月 3,2019 Leave a Reply

WordPress tax_queryでデータ取得できなかった

PHP
1
2
3
4
5
6
7
8
9
10
11
12
$args = array(
    'post_type' => 'company',
    'tax_query' => array(
        array(
            'taxonomy' => 'my-taxonomy',
            'field'    => 'slug',
            'terms'    => 'myterm',
        ),
    ),
);
 
query_posts( $args );

検索して結果が0件でした。

$query = new WP_Query($args);
print_r($query);
で確認したところ、
生成されたSQLのWHERE条件に
下記のようなSQLが出力されます。

AND wp_posts.ID NOT IN (32)
AND 0 = 1
AND …

そのおかげで検索結果が0件になります。

どうやら、WordPressでは、
tax_query 条件句を
メインクエリに追加される前に、
tax_query条件で検索し、ヒントしなかった場合、
0 = 1
をメインクエリに追加されるらしい。

私の場合、
タクソノミーの名前に問題があるようで、
定義したタクソノミーの名前:my-taxonomy
そのままの名前で検索を行うと、0件になります。
my_taxonomy
に変更したところで、

PHP
1
'taxonomy' => 'my_taxonomy',

うまくいきました。

  • Facebook
  • twitter
  • Hatena
  • Pocket

12月 23,2018 Leave a Reply

WordPress メニュー表示(class)をnav_menu_css_classフィルタでカスタマイズ

WordPressでは、wp_nav_menu関数でメニューを簡単に表示することができます。

## メニューの表示例

PHP
1
2
3
4
5
6
7
8
9
<?php
    wp_nav_menu( array(
    'theme_location' => 'primary',
    'container'  => 'nav-collapse collapse navbar-inverse-collapse',
    'menu_class' => 'nav navbar-nav navbar-left',
    'fallback_cb' => 'busiprof_fallback_page_menu',
    'walker' => new busiprof_nav_walker())
    );
?>

デフォルトでは、メニュー アイテムが選択されたときに、そのメニュー アイテムのcssのclass属性に「active」がセットされます。
※CSSで「active」を定義することで、アクティブ状態のメニュー アイテムの表示をカスタマイズできます。
 設定方法について、今回の重点ではないので、説明を割愛します。

メニュー アイテムが「アクティブ」になる条件を自前で判定したい場合、nav_menu_css_classフィルタを利用します。

nav_menu_css_classフィルタ

テーマのfunction.phpに下記のようにを定義します。

PHP
1
2
3
4
5
6
7
8
9
10
11
12
    function my_header_menu_item_classes( $classes, $item, $args ) {
        if( 'primary' !== $args->theme_location )
            return $classes;
        // 判定条件
        $curr_post_type = get_curr_post_type();         // 私の場合、現在表示されているページのpost_typeを取得し、判定したいと思います。
        if ($item->object == $curr_post_type) {      // 判定
            $classes[] = 'active';
        }
        
        return array_unique( $classes );
    }
    add_filter( 'nav_menu_css_class', 'my_header_menu_item_classes', 10, 3 );

※判定条件について、ご自身のニーズに合わせてコード修正してくださいませ。

nav_menu_css_classフィルタの
function my_header_menu_item_classes( $classes, $item, $args )
$item, $argsについて、
var_dumpしてみました。

ご参考まで

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
item=object(WP_Post)#7437 (40) {
["ID"]=> int(85)
["post_author"]=> string(1) "1"
["post_date"]=> string(19) "2018-12-08 17:40:43"
["post_date_gmt"]=> string(19) "2018-12-08 09:40:43"
["post_content"]=> string(0) ""
["post_title"]=> string(9) "メニューアイテム1"
["post_excerpt"]=> string(15) "メニューアイテム1説明"
["post_status"]=> string(7) "publish"
["comment_status"]=> string(6) "closed"
["ping_status"]=> string(6) "closed"
["post_password"]=> string(0) ""
["post_name"]=> string(18) "%e5%b7%a5%e5%8e%82"
["to_ping"]=> string(0) ""
["pinged"]=> string(0) ""
["post_modified"]=> string(19) "2018-12-15 21:50:48"
["post_modified_gmt"]=> string(19) "2018-12-15 13:50:48"
["post_content_filtered"]=> string(0) ""
["post_parent"]=> int(0)
["guid"]=> string(56) "http://yourdomain.com/wp/xxx/"
["menu_order"]=> int(2)
["post_type"]=> string(13) "nav_menu_item"
["post_mime_type"]=> string(0) ""
["comment_count"]=> string(1) "0"
["filter"]=> string(3) "raw"
["db_id"]=> int(85)
["menu_item_parent"]=> string(1) "0"
["object_id"]=> string(1) "0"
["object"]=> string(7) "menuitem1"
["type"]=> string(17) "post_type_archive"
["title"]=> string(9) "メニューアイテム1"
["type_label"]=> string(18) "Archive"
["url"]=> string(45) "http://yourdomain.com/wp/menuitem1/"
["target"]=> string(0) ""
["attr_title"]=> string(15) "メニューアイテム1説明"
["description"]=> string(0) ""
["classes"]=> array(4) { [0]=> string(0) "" [1]=> string(9) "menu-item" [2]=> string(32) "menu-item-type-post_type_archive" [3]=> string(24) "menu-item-object-menuitem1" }
["xfn"]=> string(0) ""
["current"]=> bool(false)
["current_item_ancestor"]=> bool(false)
["current_item_parent"]=> bool(false) }
 
 
 
args=object(stdClass)#7282 (18) {
["menu"]=> object(WP_Term)#7425 (10) {
["term_id"]=> int(2)
["name"]=> string(10) "HeaderMenu"
["slug"]=> string(10) "headermenu"
["term_group"]=> int(0)
["term_taxonomy_id"]=> int(2)
["taxonomy"]=> string(8) "nav_menu"
["description"]=> string(0) ""
["parent"]=> int(0)
["count"]=> int(8)
["filter"]=> string(3) "raw" }
["container"]=> string(45) "nav-collapse collapse navbar-inverse-collapse"
["container_class"]=> string(0) ""
["container_id"]=> string(0) ""
["menu_class"]=> string(26) "nav navbar-nav navbar-left"
["menu_id"]=> string(0) ""
["echo"]=> bool(true)
["fallback_cb"]=> string(27) "busiprof_fallback_page_menu"
["before"]=> string(0) ""
["after"]=> string(0) ""
["link_before"]=> string(0) ""
["link_after"]=> string(0) ""
["items_wrap"]=> string(36) "%3$s"
["item_spacing"]=> string(8) "preserve"
["depth"]=> int(0)
["walker"]=> object(busiprof_nav_walker)#7424 (4) {
["tree_type"]=> array(3) { [0]=> string(9) "post_type" [1]=> string(8) "taxonomy" [2]=> string(6) "custom" }
["db_fields"]=> array(2) {
["parent"]=> string(16) "menu_item_parent"
["id"]=> string(5) "db_id" }
["max_pages"]=> int(1)
["has_children"]=> NULL }
["theme_location"]=> string(7) "primary"
["has_children"]=> bool(false) }
  • Facebook
  • twitter
  • Hatena
  • Pocket

12月 14,2018 Leave a Reply

WordPress wp-config.phpをいじった後管理画面不調になった

現象:
1)プラグイン新規追加画面にて、キーワードを検索してもなかなか帰ってこない。
2)カテゴリーを編集したところ、編集後、管理画面が真っ白になりますが、更新が正しく反映されている
3)メディア管理画面に「画像」が存在しているが、表示されない(検索中マークがずっと表示されている状態)

対処
1)自前のfunction.phpを全て空にしましたが、改善されない
2)使っているプラグインを全て停止にしました。これも改善されない
3)wp-config.phpが 「UTF-8」になっていたことが原因だった。
  wp-config.phpを開き、ANSIに設定して保存!

下記記事を参考になりました。助かりました。ありがとうございました。
– WordPressの管理画面が真っ白になったときの対処法

  • Facebook
  • twitter
  • Hatena
  • Pocket

Our Testimonials

We are a group of passionate designers & developers

img

We are group of passionate designers and developers who really love to create wordpress themes with amazing support. Widest laborum dolo rumes fugats untras. Ethar omnis iste natus error sit voluptatem accusantiexplicabo. Nemo enim ipsam eque porro quisquam est, qui dolorem ipsum am quaerat voluptatem...

Robert Johnson (CEO & Founder)
img

We are group of passionate designers and developers who really love to create wordpress themes with amazing support. Widest laborum dolo rumes fugats untras. Ethar omnis iste natus error sit voluptatem accusantiexplicabo. Nemo enim ipsam eque porro quisquam est, qui dolorem ipsum am quaerat voluptatem...

Annah Doe (Team Leader)

All Rights Reserved by BusiProf. Designed and Developed by WordPress Theme.