wordpress调用函数大全.docx

上传人:b****6 文档编号:6285919 上传时间:2023-01-05 格式:DOCX 页数:10 大小:19.23KB
下载 相关 举报
wordpress调用函数大全.docx_第1页
第1页 / 共10页
wordpress调用函数大全.docx_第2页
第2页 / 共10页
wordpress调用函数大全.docx_第3页
第3页 / 共10页
wordpress调用函数大全.docx_第4页
第4页 / 共10页
wordpress调用函数大全.docx_第5页
第5页 / 共10页
点击查看更多>>
下载资源
资源描述

wordpress调用函数大全.docx

《wordpress调用函数大全.docx》由会员分享,可在线阅读,更多相关《wordpress调用函数大全.docx(10页珍藏版)》请在冰豆网上搜索。

wordpress调用函数大全.docx

wordpress调用函数大全

WordPress中模版代码

WordPress中的文件

style.css样式表文件

index.php主页文件

single.php日志单页文件

page.php页面文件

archvie.php分类和日期存档页文件

searchform.php搜索表单文件

search.php搜索页面文件

comments.php留言区域文件(包括留言列表和留言框)

404.php404错误页面

header.php网页头部文件

sidebar.php网页侧边栏文件

footer.php网页底部文件

WordPressHeader头部PHP代码

注:

也就是位于和之间的PHP代码

phpbloginfo(’name’);?

>网站标题

phpwp_title();?

>日志或页面标题

phpbloginfo(’stylesheet_url’);?

>WordPress主题样式表文件style.css的相对地址

phpbloginfo(’pingback_url’);?

>WordPress博客的Pingback地址

phpbloginfo(’template_url’);?

>WordPress主题文件的相对地址

phpbloginfo(’version’);?

>博客的Wordpress版本

phpbloginfo(’atom_url’);?

>WordPress博客的Atom地址

phpbloginfo(’rss2_url’);?

>WordPress博客的RSS2地址

phpbloginfo(’url’);?

>WordPress博客的绝对地址

phpbloginfo(’name’);?

>WordPress博客的名称

phpbloginfo(’html_type’);?

>网站的HTML版本

phpbloginfo(’charset’);?

>网站的字符编码格式

WordPress主体模板PHP代码

phpthe_content();?

>日志内容

phpif(have_posts()):

?

>确认是否有日志

phpwhile(have_posts()):

the_post();?

>如果有,则显示全部日志

phpendwhile;?

>结束PHP函数”while”

phpendif;?

>结束PHP函数”if”

phpget_header();?

>header.php文件的内容

phpget_sidebar();?

>sidebar.php文件的内容

phpget_footer();?

>footer.php文件的内容

phpthe_time(’m-d-y’)?

>显示格式为”02-19-08″的日期

phpcomments_popup_link();?

>显示一篇日志的留言链接

phpthe_title();?

>显示一篇日志或页面的标题

phpthe_permalink()?

>显示一篇日志或页面的永久链接/URL地址

phpthe_category(’,‘)?

>显示一篇日志或页面的所属分类

phpthe_author();?

>显示一篇日志或页面的作者

phpthe_ID();?

>显示一篇日志或页面的ID

phpedit_post_link();?

>显示一篇日志或页面的编辑链接

phpget_links_list();?

>显示Blogroll中的链接

phpcomments_template();?

>comments.php文件的内容

phpwp_list_pages();?

>显示一份博客的页面列表

phpwp_list_cats();?

>显示一份博客的分类列表

phpnext_post_link(’%link‘)?

>下一篇日志的URL地址

phpprevious_post_link(’%link’)?

>上一篇日志的URL地址

phpget_calendar();?

>调用日历

phpwp_get_archives()?

>显示一份博客的日期存档列表

phpposts_nav_link();?

>显示较新日志链接(上一页)和较旧日志链接(下一页)

phpbloginfo(’description’);?

>显示博客的描述信息

其它的一些Wordpress模板代码

/%postname%/显示博客的自定义永久链接

phpthe_search_query();?

>搜索表单的值

php_e(’Message’);?

>打印输出信息

phpwp_register();?

>显示注册链接

phpwp_loginout();?

>显示登入/登出链接

–nextpage–>在日志或页面中插入分页

–more–>截断日志

phpwp_meta();?

>显示管理员的相关控制信息

phptimer_stop

(1);?

>显示载入页面的时间

phpechoget_num_queries();?

>显示载入页面查询

1.wordpress调用最新文章

WordPress最新文章的调用可以使用一行很简单的模板标签wp_get_archvies来实现.代码如下:

phpget_archives('postbypost',10);?

>(显示10篇最新更新文章)

或者

phpwp_get_archives(‘type=postbypost&limit=20&format=custom’);?

>

后面这个代码显示你博客中最新的20篇文章,其中format=custom这里主要用来自定义这份文章列表的显示样式。

具体的参数和使用方法你可以参考官方的使用说明-wp_get_archvies。

(fromat=custom也可以不要,默认以UL列表显示文章标题。

补充:

通过WP的query_posts()函数也能调用最新文章列表,虽然代码会比较多一点,但可以更好的控制Loop的显示,比如你可以设置是否显示摘要。

具体的使用方法也可以查看官方的说明。

2.wordpress调用随机文章

php

$rand_posts=get_posts('numberposts=10&orderby=rand');

foreach($rand_postsas$post):

?

>

--下面是你想自定义的Loop-->

  • phpthe_permalink();?

    >">

    phpthe_title();?

    >

  • phpendforeach;?

    >

    3.wordpress调用最新留言

    下面是我之前在一个Wordpress主题中代到的最新留言代码,具体也记不得是哪个主题了。

    该代码直接调用数据库显示一份最新留言。

    其中LIMIT10限制留言显示数量。

    绿色部份则是每条留言的输出样式。

    php

    global$wpdb;

    $sql="SELECTDISTINCTID,post_title,post_password,comment_ID,

    comment_post_ID,comment_author,comment_date_gmt,comment_approved,

    comment_type,comment_author_url,

    SUBSTRING(comment_content,1,30)AScom_excerpt

    FROM$wpdb->comments

    LEFTOUTERJOIN$wpdb->postsON($wpdb->ment_post_ID=

    $wpdb->posts.ID)

    WHEREcomment_approved='1'ANDcomment_type=''AND

    post_password=''

    ORDERBYcomment_date_gmtDESC

    LIMIT10";

    $comments=$wpdb->get_results($sql);

    $output=$pre_HTML;  foreach($commentsas$comment){

    $output.="n

  • ".strip_tags($comment->comment_author)

    .":

    "."ID).

    "#comment-".$comment->comment_ID.""title="on".

    $comment->post_title."">".strip_tags($comment->com_excerpt)

    ."

  • ";

    }  $output.=$post_HTML;

    echo$output;?

    >

    4.wordpress调用相关文章

    在文章页显示相关文章

    php

    $tags=wp_get_post_tags($post->ID);

    if($tags){

    $first_tag=$tags[0]->term_id;

    $args=array(

    'tag__in'=>array($first_tag),

    'post__not_in'=>array($post->ID),

    'showposts'=>10,

    'caller_get_posts'=>1

    );

    $my_query=newWP_Query($args);

    if($my_query->have_posts()){

    while($my_query->have_posts()):

    $my_query->the_post();?

    >

  • phpthe_permalink()?

    >"rel="bookmark"title="

    phpthe_title_attribute();?

    >">

    phpthe_title();?

    >

    phpcomments_number('','

    (1)','(%)');?

    >

  • php

    endwhile;

    }

    }

    wp_reset_query();

    ?

    >

    5.wordpress调用指定分类的文章

    php$posts=get_posts("category=4&numberposts=10");?

    >

    phpif($posts):

    ?

    >

      phpforeach($postsas$post):

      setup_postdata($post);?

      >

    • phpthe_permalink()?

      >"rel="bookmark"title="

      phpthe_title();?

      >">

      phpthe_title();?

      >

    • phpendforeach;?

      >

    phpendif;?

    >

    6.wordpress去评论者链接的评论输出

    php

    global$wpdb;

    $sql="SELECTDISTINCTID,post_title,post_password,comment_ID,

    comment_post_ID,comment_author,comment_date_gmt,comment_approved,

    comment_type,comment_author_url,

    SUBSTRING(comment_content,1,14)AScom_excerpt

    FROM$wpdb->comments

    LEFTOUTERJOIN$wpdb->postsON($wpdb->ment_post_ID=

    $wpdb->posts.ID)

    WHEREcomment_approved='1'ANDcomment_type=''AND

    post_password=''

    ORDERBYcomment_date_gmtDESC

    LIMIT10";

    $comments=$wpdb->get_results($sql);

    $output=$pre_HTML;

    foreach($commentsas$comment){

    $output.="\n

  • ".strip_tags($comment->comment_author)

    .":

    "."ID).

    "#comment-".$comment->comment_ID."\"title=\"on".

    $comment->post_title."\">".strip_tags($comment->com_excerpt)

    ."

  • ";

    }

    $output.=$post_HTML;

    echo$output;?

    >

    7.wordpress调用含gravatar头像的评论输出

    php

    global$wpdb;

    $sql="SELECTDISTINCTID,post_title,post_password,comment_ID,comment_post_ID,comment_author,comment_date_gmt,comment_approved,comment_author_email,comment_type,comment_author_url,SUBSTRING(comment_content,1,10)AScom_excerptFROM$wpdb->commentsLEFTOUTERJOIN$wpdb->postsON($wpdb->ment_post_ID=$wpdb->posts.ID)WHEREcomment_approved='1'ANDcomment_type=''ANDcomment_author!

    ='郑永'ANDpost_password=''ORDERBYcomment_date_gmtDESCLIMIT10";

    $comments=$wpdb->get_results($sql);

    $output=$pre_HTML;

    foreach($commentsas$comment){

    $output.="\n

  • ".get_avatar(get_comment_author_email('comment_author_email'),18)."ID)."#comment-".$comment->comment_ID."\"title=\"".$comment->post_title."上的评论\">".strip_tags($comment->comment_author).":

    ".strip_tags($comment->com_excerpt)."

  • ";

    }

    $output.=$post_HTML;

    $output=convert_smilies($output);

    echo$output;

    ?

    >

    上面代码把comment_author的值改成你的ID,18是头像大小,10是评论数量。

    8.wordpress调用网站统计大全

    1、日志总数:

    php$count_posts=wp_count_posts();echo$published_posts=$count_posts->publish;?

    >

    2、草稿数目:

    php$count_posts=wp_count_posts();echo$draft_posts=$count_posts->draft;?

    >

    3、评论总数:

    phpecho$wpdb->get_var("SELECTCOUNT(*)FROM$wpdb->comments");?

    >

    4、成立时间:

    phpechofloor((time()-strtotime("2008-8-18"))/86400);?

    >

    5、标签总数:

    phpecho$count_tags=wp_count_terms('post_tag');?

    >

    6、页面总数:

    php$count_pages=wp_count_posts('page');echo$page_posts=$count_pages->publish;?

    >

    7、分类总数:

    phpecho$count_categories=wp_count_terms('category');?

    >

    8、链接总数:

    php$link=$wpdb->get_var("SELECTCOUNT(*)FROM$wpdb->linksWHERElink_visible='Y'");echo$link;?

    >

    9、用户总数:

    php$users=$wpdb->get_var("SELECTCOUNT(ID)FROM$wpdb->users");echo$users;?

    >

    10、最后更新:

    php$last=$wpdb->get_results("SELECTMAX(post_modified)ASMAX_mFROM$wpdb->postsWHERE(post_type='post'ORpost_type='page')AND(post_status='publish'ORpost_status='private')");$last=date('Y-n-j',strtotime($last[0]->MAX_m));echo$last;?

    >

    9.wordpress判断语句

    is_single()

    判断是否是具体文章的页面

    is_single(’2′)

    判断是否是具体文章(id=2)的页面

    is_single(’BeefStew’)

    判断是否是具体文章(标题判断)的页面

    is_single(’beef-stew’)

    判断是否是具体文章(slug判断)的页面

    comments_open()

    是否留言开启

    pings_open()

    是否开启ping

    is_page()

    是否是页面

    is_page(’42′)

    id判断,即是否是id为42的页面

    is_page(’AboutMe’)

    判断标题

    is_page(’about-me’)

    slug判断

    is_category()

    是否是分类

    is_category(’6′)

    id判断,即是否是id为6的分类

    is_category(’Cheeses’)

    分类title判断

    is_category(’cheeses’)

    分类slug判断

    in_category(’5′)

    判断当前的文章是否属于分类5

    is_author()

    将所有的作者的页面显示出来

    is_author(’1337′)

    显示authornumber为1337的页面

    is_author(’EliteHacker’)

    通过昵称来显示当前作者的页面

    is_author(’elite-hacker’)

    下面是通过不同的判断实现以年、月、日、时间等方式来显示归档

    is_date()

    is_year()

    is_month()

    is_day()

    is_time()

    判断当前是否是归档页面

    is_archive()

    判断是否是搜索

    is_search()

    判断页面是否404

    is_404()

    判断是否翻页,比如你当前的blog是显示?

    paged=2的时候,这个判断将返回真,通过这个函数可以配合is_home来控制某些只能在首页显示的界面,

    例如:

    phpif(is_single()):

    ?

    >

    //这里写你想显示的内容,包括函数

    phpendif;?

    >

    或者:

    phpif(is_home()&&!

    is_paged()):

    ?

    >

    //这里写你想显示的内容,包括函数

    phpendif;?

    >

    10.wordpress非插件调用评论表情

    --smilies-->       

    php

    functionwp_smilies(){

    global$wpsmiliestrans;

    if(!

    get_option('use_smilies')or(empty($wpsmiliestrans)))return;

    $smilies=array_unique($wpsmiliestrans);

    $link='';

    foreach($smiliesas$key=>$smile){

    $file=get_bloginfo('wpurl').'/wp-includes/images/smilies/'.$smile;

    $value="".$key."";

    $img="";

    $imglink=htmlspecialchars($img);

    $link.="{$img} ";

    }

    echo'

    '.$link.'
    ';

    }

    ?

    >

    phpwp_smilies();?

    >

    --smilies—>

    将以上代码复制到comments.php中合适的位置。

    展开阅读全文
    相关资源
    猜你喜欢
    相关搜索

    当前位置:首页 > 表格模板 > 合同协议

    copyright@ 2008-2022 冰豆网网站版权所有

    经营许可证编号:鄂ICP备2022015515号-1