我们在开发一款wordpress主题的时候,首先做好html静态模板后往往还需要将静态的html模板转为动态的php模板,因为只有这样才能结合wordpress做数据动态调用,下面小聪将为大家列出我们在开发wordpress主题single.php文章文件所用到的调用代码函数。
面包屑导航文章标题获取代码:
<?php if ( have_posts () ) : while ( have_posts () ) : the_post (); ?>
<?php the_title(); ?>
<?php endwhile; ?>
<?php endif; ?>
调用文章内容主循环代码:
<?php if ( have_posts () ) : while ( have_posts () ) : the_post (); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif; ?>
获取作者用户名代码:
<?php if ( have_posts () ) : while ( have_posts () ) : the_post (); ?>
<?php the_author(); ?>
<?php endwhile; ?>
<?php endif; ?>
获取发布日期代码:
<?php the_time('Y/m/d H:i:s'); ?>
获取相关文章信息主循环代码:
<?php $wpahz_posts = new WP_Query(
array(
'post_type' => 'post', //自定义文章类型,这里为course
'ignore_sticky_posts' => 1, //忽略置顶文章
'posts_per_page' => 10, //显示的文章数量
'tax_query' => array(
array(
'taxonomy' => 'category', //分类法名称
'field' => 'id', //根据分类法条款的什么字段查询,这里设置为ID
'terms' => array(1), //分类法条款,输入分类的ID,多个ID使用数组:array(1,2)
'include_children' => true,
'operator' => 'IN',
),
),
)
);
?>
<?php if ( $wpahz_posts->have_posts () ) : while ( $wpahz_posts->have_posts () ) : $wpahz_posts->the_post (); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a><span style="color: #999; padding-left: 10px;" class="little">(<?php echo getPostViews(get_the_ID()); ?> 次阅读)</span></li>
<?php endwhile; ?>
<?php endif; ?>
调用文章列表菜单导航代码:
<?php $my_nav = array(
'theme_location' => 'list_menu_january', //[保留]
'menu' => '', //[可删]
'container' => false, //[可删]
'container_class' => '', //[可删]
'container_id' => '', //[可删]
'menu_class' => 'menu', //[可删]
'menu_id' => '', //[可删]
'echo' => false, //[可删]
'fallback_cb' => 'wp_page_menu', //[可删]
'before' => '', //[可删]
'after' => '', //[可删]
'link_before' => '', //[可删]
'link_after' => '', //[可删]
'items_wrap' => '%3$s', //[可删]
'depth' => -1, //[可删]
'walker' => '' //[可删]
);
echo strip_tags(wp_nav_menu( $my_nav ), '<li><a>' );
?>