WordPress commonly used label calls

People who are accustomed to the cms background management system of dream weaving will always feel uncomfortable when using wordpress again. Dream weaving has many tag calling software, which can be very convenient to use tags for custom development of website templates, and wordpress has a wealth of themes that can be used , But when some themes cannot meet our needs, you need to develop themes yourself. Of course, you need to use WordPress to call tags to develop WordPress themes. The following is a summary of the calls of some WordPress commonly used tags. Let’s take a look.

WordPress commonly used label calls

1. WordPress system label call

<?php get_header(); ?>  //头部调用
<?php get_footer(); ?>  //底部调用
<?php get_sidebar(); ?> //右侧边栏调用
<?php get_template_part( 'link' ); ?>  //引用自定义link.php
<?php get_template_part( 'link', 'head' ); ?>  //引用自定义link.php 意思是说,如果link.php存在,则调用link.php,否则,就调用head.php
<?php   /*Template Name: about*/  ?>  //自定义模板调用, 在自定义模板头部添加
<?php get_links_list(); ?>  //友情链接调用

2. Wordpress css/js/img path address call tag

href="<?php bloginfo('template_url'); ?>/css/abc.css"  //css路径地址

src="<?php bloginfo('template_url'); ?>/images/abc.jpg"  //图片路径地址

src="<?php bloginfo('template_url'); ?>/js/jbc.js"  //js路径地址

<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />  //绝对地址

3. WordPress navigation call label

//wordpress导航调用
<ul>
<?php wp_list_pages('depth=1&title_li=0&sort_column=menu_order'); ?>
    <li <?php if (is_home()) { echo 'class="current"';} ?> >
        <a title="<?php bloginfo('name'); ?>" href="<?php echo get_option('home'); ?>">
        <?php bloginfo('name'); ?>
        </a>
    </li>
</ul>

//wordpress导航调用获取页面导航
<ul id="menu">
<?php
$mypages = get_pages();

if(count($mypages) > 0) {
    foreach($mypages as $page) {
        echo '<li><a href="'.get_page_link($page->ID).'" title="'.$page->post_title.'">'.$page->post_title.'</a></li>';
    }
}
else {
    echo '<li><a href="#">没有页面</a></li>';
}
?>
</ul>

//导航调用获取分类导航
<ul id="menu">		
<?php
	// 获取分类
	$terms = get_terms('category', 'orderby=name&hide_empty=0' );

	// 获取到的分类数量
	$count = count($terms);
	if($count > 0){
		// 循环输出所有分类信息
		foreach ($terms as $term) {
			echo '<li><a href="'.get_term_link($term, $term->slug).'" title="'.$term->name.'">'.$term->name.'</a></li>';
		}
 	}
?>		
</ul>

4. The category catalog calls the call label

<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('First_sidebar') ) : ?>
		<h4>分类目录</h4>
		<ul class="sidebar">
			<?php wp_list_categories('depth=1&title_li=&orderby=id&show_count=0&hide_empty=1&child_of=0'); ?>
		</ul>
<?php endif; ?>

5. The wordpress list page calls tags in a loop

/*列表循环*/
<?php if(have_posts()) : ?>
    <?php while(have_posts()) : the_post(); ?> 
    <?php endwhile; ?>
<?php endif; ?>
<?php else:?>
    <div class="post" id="post-<?php the_ID(); ?>">
<?php _e('Not Found');?>


//列表循环例子

<div id="content">
    <?php if(have_posts()) : ?> <!--开始检测-->
    <?php while(have_posts()) : the_post(); ?><!--以下面的格式显示每篇日志-->
        <div class="post">
            <h2><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>/*调用文章链接 文章标题*/
            <div class="entry">
                <?php the_content();?><!--文章内容-->
                <p class="postmetadata"><!--文章元数据-->
                <?php _e('Filed under:');?>
                <?php the_category(',');?><!--调用文章的分类-->
                <?php _e('by');?><!--使用_e()创建可翻译的主题-->
                <?php the_autnor('');?><!--调用文章作者-->
                <br />
                <?php comments_poopup_link('No Comments?','1 Comments?','% Comment?');?><!--调用一个弹出的留言窗口,如果这个功能没有激活,则是显示留言列表-->
                <?php edit_post_link('Edit','|','');?><!--只有在登陆后才可见到,对日志进行编辑的链接-->
                </p>
            </div><!--日志内容结束-->
        </div><!--一篇日志彻底结束-->
    <?php endwhile; ?>
    <?php endif; ?>
	
   <div class="navigation">
        <?php posts_nav_link(); ?> //上一页下一页
    </div>

    <?php else:?> //如果没有文章显示的内容
       <div class="post" id="post-<?php the_ID(); ?>">
    <?php _e('Not Found');?>
	
</div>

6, WordPress latest article list page to call tags in a loop

<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('First_sidebar') ) : ?>
		<h4>最新文章</h4>
		<ul class="sidebar">
			<?php
				$posts = get_posts('numberposts=6&orderby=post_date');
				foreach($posts as $post) {
					setup_postdata($post);
					echo '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
				}
				$post = $posts[0];
			?>
		</ul>
<?php endif; ?>

7. The home page list is called cyclically


<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
	文章html骨架
<?php endwhile; ?>
<?php else : ?>
	输出找不到文章提示
<?php endif; ?>

8. WordPress article content call tags

<?php echo get_option('home'); ?>  //输出网站首页网址
<?php bloginfo('name'); ?>  //输出你网站的名字
<?php the_permalink(); ?>  //输出当前文章的URL地址
<?php the_title(); ?>     //输出当前文章的标题
<?php the_excerpt(); ?>  //当前文章网站描述
<?php the_content(); ?>    //输出文章内容
<?php the_author(); ?>    //输出作者
<?php the_time('y-m-d H:i:s') ?>  //输入文章日期  或者(<?php the_time('Y年m月d日') ?>)
<?php comments_popup_link('0 条评论', '1 条评论', '% 条评论', '', '评论已关闭'); ?>  //输出评论数
<?php single_cat_title(); ?>   //当前栏目名
<?php the_excerpt(); ?>   //输出文章摘要  文章没有填写摘要会输入全文
<?php the_content('阅读全文...'); ?>   //输出全文
<?php the_permalink(); ?>  //阅读全文链接
<?php echo category_description(); ?>  //分类目录描述调用
<?php tag_description(); ?>    //标签分类描述调用
<?php echo mb_strimwidth(get_the_title(), 0, 40, '...'); ?>  //调用文章标题限制字符数
<?php echo get_avatar( get_the_author_email(), 36 ); ?>   //调用作者的头像

 

Guess you like

Origin blog.csdn.net/qq_39339179/article/details/111544247