zoukankan      html  css  js  c++  java
  • wordpress主题开发-部分函数调用整理

    <?php echo $post->post_content;?>  //文章内容

    <?php echo $post->post_title;?>  //标题

    <?php echo get_the_author_meta( 'display_name', $post->post_author )?>  //作者

    <?php echo get_post_meta($post->ID, '演示地址', true); ?>  //获取自定义字段为“演示地址”的值

    <?php echo $post->post_excerpt;?>  //摘要<?php echo $post->post_excerpt;?>  //摘要

    <?php $category = get_the_category();if($category[0]){echo get_category_link($category[0]->term_id );}?>  //调用当前文章所属分类的链接,用于返回列表

    <?php $cat=get_category_by_slug('news-gs');echo get_category_link($cat->term_id);?>   //指定分类别名,获取该别名分类的链接

    <?php echo get_template_directory_uri();?>  //获取主题目录

    <?php//指定文章分类,方便调用上一页下一页在同一个分类
    $categories = get_the_category();
    $categoryIDS = array();
    foreach ($categories as $category) {
    array_push($categoryIDS, $category->term_id);
    }
    $categoryIDS = implode(",", $categoryIDS);
    ?>
    <?php if (get_previous_post($categoryIDS)) { previous_post_link('%link','%title',true);} else { echo "已是最后一篇文章";} ?>
    <?php if (get_next_post($categoryIDS)) { next_post_link('%link','%title',true);} else { echo "已是最新的文章";} ?>

    文章的循环输出:

    <?php if( have_posts() ) : while( have_posts() ) : the_post(); ?>
    循环文章调用
    <?php endwhile; ?>

    文章的分页

    <div class="shebei-fanye"><?php wp_pagenavi(); ?></div>
    <?php endif; ?>

    functions.php代码:

    function wp_pagenavi() {
    global $wp_query, $wp_rewrite;
    //判断当前页面
    $wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;

    $pagination = array(
    'base' => @add_query_arg('paged','%#%'),
    'format' => '',
    'total' => $wp_query->max_num_pages, //总共显示的页码数
    'current' => $current, //当前页码数
    'show_all' => false, //是否将所有页码都显示出来,需配合下两个参数
    'type' => 'plain',
    'end_size'=>'1', //在最后面和最前面至少显示多少个数,
    'mid_size'=>'3', //在当前页码的前后至少显示多少个页码数
    'prev_text' => '<', //是否显示“上一页”“下一页”链接
    'next_text' => '>'
    );

    if( $wp_rewrite->using_permalinks() )
    $pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg('s',get_pagenum_link(1) ) ) . 'page/%#%/', 'paged');
    if( !empty($wp_query->query_vars['s']) )
    $pagination['add_args'] = array('s'=>get_query_var('s'));
    echo paginate_links($pagination);
    }

  • 相关阅读:
    Struts2 文件上传和下载
    Struts2的验证框架简单吗?
    Struts2防止重复提交
    Struts2的标签三大类是什么?
    Struts2的值栈和OGNL牛逼啊
    Struts2牛逼的拦截器,卧槽这才是最牛的核心!
    转载---C# 递归创建文件夹
    转载---C# 冻结 datagridview的列
    C# base64编码转成图片
    转载---C# 复制文件夹下的(内容)到指定文件夹中
  • 原文地址:https://www.cnblogs.com/duolaAmengblog/p/13083218.html
Copyright © 2011-2022 走看看