我们在开发一款wordpress主题的时候,首先做好html静态模板后往往还需要将静态的html模板转为动态的php模板,因为只有这样才能结合wordpress做数据动态调用,下面小聪将为大家列出我们在开发wordpress主题index.php首页文件所用到的调用代码函数。
获取文章链接调用代码:
<?php the_permalink() ?>
获取文章标题调用代码:
<?php the_title(); ?>
调用文章列表信息循环体代码:
<?php $wpahz_posts = new WP_Query(
array(
'post_type' => 'course', //自定义文章类型,这里为course
'ignore_sticky_posts' => 1, //忽略置顶文章
'posts_per_page' => 4, //显示的文章数量
'paged' => get_query_var('paged'), //开启分页功能
'tax_query' => array(
array(
'taxonomy' => 'wcourse', //分类法名称
'field' => 'id', //根据分类法条款的什么字段查询,这里设置为ID
'terms' => array(83), //分类法条款,输入分类的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 (); ?>
<div>这里是需要调用的HTML代码</div>
<?php endwhile; ?>
<?php endif; ?>
调用文章自定义字段代码:
<?php echo get_post_meta($post->ID, "my_img_value", true); ?>
调用文章作者代码:
<?php the_author(); ?>