• 10个鲜为人知的WordPress函数


    WordPress功能强大,非常适合开发者使用。说到 WordPress,那么,我们不得不说他的钩子函数。今天,要为大家推荐10个WordPress函数。大多数,都是我们常用的功能,不过,经常不知道如何去实现他。所以,我建议你可以看一看。

    Antispambot()

    使用该函数代替HTML标题,可以让你的email地址不被过滤掉。

    $email= 'mymail@mail.com';
    echo'You can contact me at '. antispambot( $email) . ' any time'.

    Human_time_diff()

    该函数使用文章发布日期为第一讨论日期,当前日期为第二日期。

    echo'This post was published '. human_time_diff( get_the_time( 'U'), current_time( 'timestamp') ) . ' ago';

     

    Get_post_meta()

    该功能很好用,但是却不好操作,省略第二和第三参数,可以找出一篇文章的所有元数据。

     

    $all_meta= get_post_meta( 14 );


    Wp_upload_bits()

    直接上传文件功能,不需要你将文件传到文件夹或者WP媒体选项,非常方便。

    $upload= wp_upload_bits( $file['name'], null, file_get_contents( $file['tmp_name'] ) );
    
    

    Get_post_field()

    该函数可以在单一文章中索检单个字段值。

    This post has <!--?php echoget_post_field( 'comment_count', 4124 ) ?--> comments.
     


    Wpautop()

    该函数封装段落内容。

    <h2>What Our Users Say</h2>
    <!--?php echowpautop( $user_comment) ?-->
     


    Wp_is_mobile()

    该命名函数,在用户使用移动设备时会开启检测,显示相应内容。

    <!--?php if( wp_is_mobile() ) : ?-->
    Visit our website on your desktop fora richer user experience
    <!--?php endif?-->
     


    DOING_AJAX

    你可以使用该函数识别调用AJAX和常规工作。

    if(defined('DOING_AJAX') && DOING_AJAX) {
    echo'done';
    die()
    }
    else{
    }
     


    Wp_redirect()

    设置URL重定向,并且设置状态代码,也可以处理永久重定向。

    // For a URL which is no longer in use
    wp_redirect( 'http://website.com/new-url/', 301 );
     


    Paginate_links()

    在文章列表最后显示。前一个/下一个链接。WP-PageNavi替代页码。

    global$wp_query;
    $big= 999999999; // need an unlikely integer
    echopaginate_links( array(
    'base'=> str_replace( $big, '%#%', esc_url( get_pagenum_link( $big) ) ),
    'format'=> '?paged=%#%',
    'current'=> max( 1, get_query_var('paged') ),
    'total'=> $wp_query->max_num_pages
    ) );
     


    总结

    在我们不知道的 WordPress 函数海洋,这只是很小的一部分。我也会继续发掘分享,如果你有新发现,欢迎分享!

    来自:http://www.topthink.com/topic/7609.html
  • 相关阅读:
    阿里云播放器弹幕选型
    使用swiper组件,轮播图在高分辨率情况下变形,图片拉高该如何解决?
    解决图片无法设置hover,以设置图片的阴影
    当标题文字超出长度后,后续用...来代替
    windows 安装wget
    【Go学习】GO中...的用法
    【Go】go test
    tcpdump工具及使用介绍
    leetcode32.最长有效括号
    Global Round 21 部分题解
  • 原文地址:https://www.cnblogs.com/webqiand/p/4434631.html
Copyright © 2020-2023  润新知