wordpress常用调用标签

调用头部:<?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(); ?&
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值