最近帮朋友仿站,对wordpress的代码调用做一个记录,以备后面使用。
仿站准备:
wordpress代码以及释义如下:
5.
显示分类目录下面的ID 为 3,5,9,16的目录,包括子目录也会有下级目录,这个目录就是后台的:文章-》分类目录
6. 这个就把5的“分类目录”几个字去掉了
7. //show_count=1显示文章数量;//use_desc_for_title=0不显示标题描述
//child_of=9显示ID为9的子类//&title_li=产品显示分类目录的名称为产品
8. 调用某个页面的链接并且链接的名称为空(为空自动将页面名称链接显示)
由于php wp_list_categories 的child_of只能是子目录的链接,所以加上ul li以及wp_list_categories(‘include=9&title_li=&style=’); 将主链接调取出来
$cat_id = get_category_by_slug('products');
echo get_category_link($cat_id->term_id);
guid;
$pageTitle = $page_data->post_title;
$pageContent = $page_data->post_content;
?>
term_id;
$args=array(
'category' => $cat_id,
'numberposts' => '4',
'order'=>'date'
);
$posts = get_posts( $args );
if( $posts ) :
foreach( $posts as $post ) : setup_postdata( $post ); ?>
3,
'prev_text' =>'上一页',
'next_text' =>'下一页',
'before_page_number' => '
',
'after_page_number' => ' ',
) ); ?>
term_id;
$args=array(
'category' => $cat_id,
'numberposts' => '4'
);
$posts = get_posts( $args );
if( $posts ) : foreach( $posts as $post ) : setup_postdata( $post ); ?>
调用文章标题:
调用文章内容:
调用文章摘要:
调用作者姓名:
调用文章发布时间:
'name',
'order' => 'ASC'
);
$categories=get_categories($args);
foreach($categories as $category) {
echo 'Category: name ) . '" ' . '>' . $category->name.'
';
echo ' Description:'. $category->description . '
';
echo ' Post Count: '. $category->count . '
';
}
?>
term_id;
//echo $cat_id;
$args=array(
'child_of'=> $cat_id
);
$categories=get_categories($args);
foreach($categories as $category) {
//echo $category->category_parent.'
';
if($category->category_parent == $cat_id){
//如果他的父类为product 产品,那么他就是二级分类
?>
term_id);?>
term_id;
$child_args = array('child_of'=>$childfather_id);
$childs = get_categories($child_args);
foreach($childs as $child) {?>
term_id);?>
$cat,
'orderby'=>'name',
'numberposts' => '12'
);
$posts = get_posts($args);
if( $posts ) :
foreach( $posts as $post ) : setup_postdata( $post );
//echo the_permalink();
?>
'12',
'prev_text' =>'PRE',
'next_text' =>'NEXT',
'before_page_number' => ' ',
'after_page_number' => ' ',
) ); ?>
/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img = bloginfo('template_url') . "/static/images/default.jpg";
};
return $first_img;
}
?>
再在目录列表中调用
显示第一张图片