上一篇内容中介绍了wordpress的默认文件,如果要学习开发,那么你还得了解WordPress默认的封装代码调用标签,用于网站的标题、内容、以及一些页面的调用。
<?php language_attributes(); ?> 网站当前语言
<?php bloginfo( ‘charset’ ); ?> 网站编码
<?php bloginfo(‘name’); ?> 网站标题
<?php bloginfo(‘description’); ?> 网站副标题
<?php wp_title(); ?> 日志或页面标题
<?php bloginfo( ‘stylesheet_url’ ); ?> WordPress主题样式表文件style.css的相对地址
<?php bloginfo(‘pingback_url’); ?> WordPress博客的Pingback地址
<?php bloginfo(‘template_url’); ?> WordPress主题文件的相对地址
<?php get_header();?> WordPress主题头部文件
<?php get_footer();?> WordPress主题底部文件
<?php wp_head(); ?> Hook标签(插件)
<?php wp_nav_menu( array( ‘container’ => ”,’menu_class’ => ‘【class】’,’menu_id’ => ‘【div的id】’) ); ?> 导航菜单
<?php get_sidebar();?> 侧边栏
<?php echo get_option(‘home’); ?> 更多按钮链接
<?php bloginfo(‘version’); ?> 博客的Wordpress版本
<?php bloginfo(‘atom_url’); ?> WordPress博客的Atom地址
<?php bloginfo(‘rss2_url’); ?> WordPress博客的RSS2地址
<?php bloginfo(‘url’); ?> WordPress博客的绝对地址
<?php bloginfo(‘html_type’); ?> 网站的HTML版本
<?php the_time( ‘Y-m-d H:i:s l ‘ ) ?> 时间标签(年月日时分秒星期)
<?php next_post_link(‘%link’) ?> 下一篇日志的URL地址
<?php previous_post_link(‘%link’) ?> 上一篇日志的URL地址
<?php echo get_num_queries(); ?> 显示载入页面查询
<?php timer_stop(1); ?> 显示载入页面的时间
<!–next page–> 在日志或页面中插入分页
<?php _e(’Message’); ?> 打印输出信息
<?php wp_register(); ?> 显示注册链接
<?php wp_loginout(); ?> 显示登入/登出链接
<?php comments_template();?> 默认评论
1. wordpress调用最新文章
WordPress最新文章的调用可以使用一行很简单的模板标签wp_get_archvies来实现. 代码如下:
<?php get_archives('postbypost', 10); ?> (显示10篇最新更新文章)
或者
<?php wp_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_posts as $post ) :
?>
< !–下面是你想自定义的Loop–>
< li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> < ?php endforeach; ?>
3. wordpress调用最新留言
下面是我之前在一个Wordpress主题中代到的最新留言代码,具体也记不得是哪个主题了。该代码直接调用数据库显示一份最新留言。其中 LIMIT 10限制留言显示数量。绿色部份则是每条留言的输出样式。
<?php
global $wpdb;
$sql = "SELECT DISTINCT ID, 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) AS com_excerpt
FROM $wpdb->comments
LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID =
$wpdb->posts.ID)
WHERE comment_approved = '1' AND comment_type = '' AND
post_password = ''
ORDER BY comment_date_gmt DESC
LIMIT 10";
$comments = $wpdb->get_results($sql);
$output = $pre_HTML; foreach ($comments as $comment) {
$output .= "n<li>".strip_tags($comment->comment_author)
.":" . " <a href="" . get_permalink($comment->ID) .
"#comment-" . $comment->comment_ID . "" title="on " .
$comment->post_title . "">" . strip_tags($comment->com_excerpt)
."</a></li>";
} $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 = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title();?> <?php comments_number(' ','(1)','(%)'); ?></a></li>
<?php
endwhile;
}
}
wp_reset_query();
?>
5.wordpress调用指定分类的文章
<?php $posts = get_posts( "category=4&numberposts=10" ); ?> < ?php if( $posts ) : ?> < ul><?php foreach( $posts as $post ) : setup_postdata( $post ); ?> < li> < a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a> < /li> < ?php endforeach; ?> < /ul> < ?php endif; ?>
专注一点,放眼未来。
感谢阅读,欢迎交流实践中的新发现。
I lovved aas much as you will receive carried out rkght
here. The sjetch is tasteful, your authored material stylish.
nonetheless, you commwnd get got an neervousness ver that yoou wish be delivering thhe following.
unwell unquestionably come more formerly again ass exactly the sme
nearlyy very often inside case youu shield thi hike.
xnxx