WP+PHPスニペット

/* --------------------------- パス, 呼出し --------------------------- */ <!-- 画像 --> <img src="<?php echo get_template_directory_uri(); ?>/assets/images/xxx.jpg" alt=""> <!-- ファイル --> <link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/assets/js/slick/slick-theme.css"/> <!-- 特定記事URL --> <a href="<?php echo get_permalink(記事ID); ?>">サイトマップ</a> <!-- 固定ページURL --> <a href="<?php $page = get_page_by_path('sitemap'); echo get_permalink($page->ID); ?>">サイトマップ</a> <!-- 固定ページURL:子ページ --> <a href="<?php $page = get_page_by_path('about/sitemap'); echo get_permalink($page->ID); ?>">サイトマップ</a> <!-- 固定ページURL・タイトル生成:複数 --> <?php $page_about_sitemap = get_page_by_path('about/sitemap'); /* 固定ページ指定 */ ?> <a href="<?php echo get_permalink($page_about_sitemap->ID); ?>">コンテンツ</a> <a href="<?php echo get_permalink($page_about_sitemap->ID); ?>#b">コンテンツB</a> <a href="<?php echo get_permalink($page_about_sitemap->ID); ?>"><?php echo $page_about_sitemap->post_title; /* 固定ページのタイトル */ ?>について</a> <!-- カテゴリースラッグからURL・タイトル生成 --> <?php $cat_news = get_category_by_slug('news'); ?> <a href="<?php echo get_category_link( $cat_news->cat_ID); ?>"><?php echo get_cat_name($cat_news->cat_ID);?>一覧</a> <!-- テンプレ呼び出し --> <?php get_template_part( 'tm-contact-link' ); ?> <!-- HTMLタグ無し alt, title --> <?php the_title_attribute(); ?> /* --------------------------- ナビ --------------------------- */ <!-- current付与 --> <?php if ( is_page('XXXX') ): ?> current<?php endif; ?> <!-- カスタムメニューでナビ振り分け --> <?php if ( is_front_page() ): /* サイドナビ -- トップページ */ ?> <?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'theme_location' => 'top-treatment-menu' , 'depth' => '', 'container' => '', 'menu_class' => 'side_menu','link_before' => '<span class="icon-arrow-right2">', 'link_after' => '</span>' ) ); ?> <?php elseif ( is_page('about') or is_page('treatment') or is_parent_slug() === 'about' or is_parent_slug() === 'voice' or is_parent_slug() === 'treatment' or is_parent_slug() === 'case' ): /* 第1・第2階層 */ ?> <?php if ( is_page('about') or is_parent_slug() === 'about' or is_parent_slug() === 'voice' ): /* サイドナビ -- 当院について */ ?> <?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'theme_location' => 'about-page-menu' , 'depth' => '', 'container' => '', 'menu_class' => 'side_menu','link_before' => '<span class="icon-arrow-right2">', 'link_after' => '</span>' ) ); ?> <?php endif; ?> <?php if ( is_page('treatment') or is_parent_slug() === 'treatment' or is_parent_slug() === 'case' ): /* サイドナビ -- 治療について */ ?> <?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'theme_location' => 'treatment-page-menu' , 'depth' => '', 'container' => '', 'menu_class' => 'side_menu','link_before' => '<span class="icon-arrow-right2">', 'link_after' => '</span>' ) ); ?> <?php endif; ?> <?php endif; ?> <!--子ページ判定--> function is_subpage() { global $post; // $post には現在の固定ページの情報があります if ( is_page() && $post->post_parent ) { // 現在の固定ページが親ページを持つかどうかをチェックします return $post->post_parent; // 親ページの ID を返します } else { // 親ページを持たないので... return false; // ...false を返します }; }; <!--固定ページの親ページと子ページをスラッグで判定--> function is_parent_slug() { global $post; if ($post->post_parent) { $post_data = get_post($post->post_parent); return $post_data->post_name; } } /* --------------------------- 条件分岐 --------------------------- */ <?php if ( is_front_page() || is_page('project') || is_page('company') || is_page('recruit') || is_page('contact') ): ?> 〜処理〜 <?php endif; ?> /* --------------------------- カスタムフィールド --------------------------- */ <!-- テキスト --> <?php if( get_field('cf__p-ep--name-02') ): /* データ有無判定 */ ?> <?php the_field('cf__p-ep--name-02') ?> <?php endif; ?> <!-- 画像 --> <?php if( get_field('cf__p-ep--img') ): /* データ有無判定 */ ?> <img src="<?php the_field('cf__p-ep--img'); ?>" alt="<?php the_field('cf__p-ep--name') ?>"> <?php endif; ?> /* --------------------------- IE -- lte --------------------------- */ <?php /* IE9-8で非表示 */ $agent = getenv("HTTP_USER_AGENT"); if( !mb_ereg("MSIE 9.", $agent) && !mb_ereg("MSIE 8.", $agent) ){ ?> <link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/assets/css/normalize.css"> <link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/assets/css/fonts.css"> <link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/assets/css/style.css"> <?php } ?> <?php /* IE9-8で表示 */ $agent = getenv("HTTP_USER_AGENT"); if( mb_ereg("MSIE 9.", $agent) or mb_ereg("MSIE 8.", $agent) or mb_ereg("MSIE 7.", $agent) ){ ?> <link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/assets/css/ie-lte.css" media="all"> <?php } ?>

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.