WordPress いつも調べるやつ
テンプレートタグなど
URL出力 <?php echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?> <?php echo site_url(); ?> <?php bloginfo('template_url'); ?> title要素 <title><?php wp_title('|', true, 'right'); ?><?php bloginfo('name'); ?></title> css,RSS読み込み <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>"> <link rel="alternate" type="application/rss+xml" href="<?php bloginfo('rss2_url'); ?>"> WordPressのjQuery読み込まない <?php wp_deregister_script('jquery'); ?> head要素の最後に <?php wp_head()?> body要素 <body <?php body_class(); ?>> </body>の直前に <?php wp_footer(); ?> カテゴリーとアーカイブ出力 <?php wp_list_categories(); ?> <?php wp_get_archives(); ?> タグ一覧出力 <?php $tags = get_terms('post_tag', 'hide_empty=0'); ?> <?php foreach($tags as $value): ?> <p><a href="<?php echo get_tag_link($value->term_id); ?>"><?php echo $value->name; ?></a></p> <?php endforeach; ?> ブログ名、説明出力 <?php bloginfo('name'); ?> <?php bloginfo('description'); ?>
◯ファイル読み込み
<?php get_header(); ?> <?php get_sidebar(); ?> <?php get_footer(); ?> <?php get_template_part( 'loop' ); ?>
◯ページ分岐
is_home() is_category() is_archive() is_search() is_single() is_404() <?php if ( is_home() ) : ?> <?php elseif( is_single() ): ?> <?php else : ?> <?php endif; ?> <?php if ( !is_home() ) : ?> <?php endif; ?>
◯ループ
<?php if(have_posts()) : while(have_posts()) : the_post(); ?> <article> <p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p> <p><?php the_content(); ?></p> <p><?php the_time('Y.m.d'); ?></p> <p><?php the_category(', '); ?></p> <p><?php the_tags(); ?></p> </article> <?php endwhile; endif; ?>
◯wp_query
<?php $args = array( 'post_type' => 'post', 'posts_per_page' => 10 ); ?> <?php $loop = new WP_Query( $args ); ?> <?php if($loop -> have_posts()): ?> <?php while($loop -> have_posts()): $loop->the_post();?> <article> <p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p> <p><?php the_content(); ?></p> <p><?php the_time('Y.m.d'); ?></p> <p><?php the_category(', '); ?></p> <p><?php the_tags(); ?></p> </article> <?php endwhile; ?> <?php endif; ?> <?php wp_reset_postdata(); ?>
◯ページ送り
indexページ <?php previous_posts_link( '&laquo; 新しい投稿' ); ?> <?php next_posts_link( '古い投稿 &raquo;' ); ?> singleページ <?php next_post_link('%link','&laquo; %title'); ?> <?php previous_post_link('%link','%title &raquo;'); ?>
◯wp_pagenavi
<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>
htmlは
<div class="wp-pagenavi"> <span class="current">1</span><a href="/">2</a> </div>
◯style.css
@charset "UTF-8"; /* Theme Name: テーマ名 Author: 作者 Description: テーマの説明 Version: 1.0 */