调用头部:<?php get_header(); ?>
调用底部:<?php get_footer(); ?>
调用自定义模板文件:<?php get_template_part('list-head'); ?>
路径:<?php bloginfo('template_url'); ?>
缩略图:<?php the_post_thumbnail_url( 'full' ); ?>
调用标题:<?php the_title(); ?>
发布时间:<?php the_time('Y-m-d');?>
文章内容:<?php the_content();?>
面包屑:<?php if (function_exists('cmp_breadcrumbs')) cmp_breadcrumbs(); ?>
分类页面:
调用分类图片:<?php if (function_exists('z_taxonomy_image_url')) echo z_taxonomy_image_url(); ?>
分类目录名称:
<?php $thiscat = get_category($cat);echo $thiscat->name; ?>
菜单调用
在需要显示菜单的位置调用此代码:
<?php wp_nav_menu(array('theme_location' => 'header_menu', 'container' => false,'items_wrap' => '<ul class="nav_ul">%3$s</ul>', 'fallback_cb' => 'Bing_menu_null_fallback')); ?>
在functions.php中添加菜单功能
<?php
// 添加菜单功能
function sanyi_setup()
{
register_nav_menus([
'header_menu' => __('顶部导航'),
'footer_menu' => __('底部导航')
]);
}
add_action('after_setup_theme', 'sanyi_setup');
?>
首页循环调用指定栏目
<?php
$args = array(
'cat' => 4, // 分类ID
'posts_per_page' => 3, // 显示篇数
);
query_posts($args);
if (have_posts()) : while (have_posts()) : the_post();
?>
<div class="swiper-slide">
<!-- 文章链接 -->
<a href="<?php the_permalink(); ?>">
<div class="over">
<!-- 调用文章缩略图 -->
<img src="<?php the_post_thumbnail_url('full'); ?>" alt="" class="w100">
</div>
<div class="content">
<div class="title">
<!-- 文章标题 -->
<?php the_title(); ?>
</div>
<div class="txt">
<!-- 文章摘要 -->
<?php if (has_excerpt()) {
echo $description = get_the_excerpt(); //文章编辑中的摘要
} else {
echo mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 170, "……"); //文章编辑中若无摘要,自定截取文章内容字数做为摘要
} ?>
</div>
<div class="time">
<!-- 调用发布日期 -->
<?php echo date('M');
the_time('d,Y'); ?>
</div>
</div>
</a>
</div>
<?php endwhile;
endif;
wp_reset_query(); ?>
首页调用指定分类的二级分类
<?php
$args = array(
'include' => '1',
);
$categories = get_categories($args);
foreach ($categories as $category) { ?>
<?php
$argszi = array(
'child_of' => $category->term_id,
'parent' => $category->term_id,
'hide_empty' => '0',
'orderby' => 'ID',
'order' => 'ASC',
);
$categorieszi = get_categories($argszi);
foreach ($categorieszi as $categoryzi) {
?>
<div class="col-md-2">
<a href="<?php echo get_category_link($categoryzi->term_id); ?>">
<div class="box">
<div class="content">
<div class="en_name2"><?php echo $categoryzi->name; ?></div>
</div>
</div>
</a>
</div>
<?php }
}
?>
category分类循环调用文章
<?php while (have_posts()) : the_post(); ?>
<li class="list">
<a href="<?php the_permalink(); ?>">
<div class="over">
<img src="<?php the_post_thumbnail_url('full'); ?>" alt="<?php the_title(); ?&