wordpress网站分类列表页模板主题开发制作教程

网站分类列表页模板主题又称为聚合页,多位产品,或者文章列表页面也是网站中不可或缺的一种页面;本篇模板主题开发教程主要讲的是,列表循环,分页标签,面包屑导航等等……

wordpress网站分类列表页模板主题开发制作

一般正常的网站列表页主题主要有以下几部分组成

1、公共头部菜单导航

2、wordpress网站面包屑导航

3、wordpress网站侧边栏

4、当前列表分类的栏目名_栏目id_栏目链接

 <?php echo category_description( $category_id ); ?> //当前分类描述 <?php echo category_description(); ?> //当前分类描述 <?echo trim(strip_tags(category_description())); ?> //当前分类描述 不带默认p标签 <? $category_title= single_cat_title('', false ); $category_id = get_cat_ID($category_title); $category_link = get_category_link( $category_id ); echo $category_title; //输出当前分类名 echo $category_id; //输出当前分类id echo $category_link //输出当前分类链接 ?>

5、当前分类顶级分类栏目的分类名_链接(例:当前行业新闻,获取父分类新闻中心栏目名)

<a href="<?php echo get_category_link(get_category_root_id($cat)); ?>"><?php echo get_cat_name(get_category_root_id($cat)); ?></a>

6、当前列表栏目子分类 (functions添加获取当前分类子分类列表代码

在需要调用当前顶级分类栏目的子分类处添加如下代码 <?php if(is_single()||is_category()) { //如果是文件页面或分类页 if(get_category_children(get_category_root_id(the_category_ID(false)))!= "" ) {//如果有子分类 echo '<ul class="sidebar-list1">'; echo wp_list_categories("child_of=".get_category_root_id(the_category_ID(false)). "&depth=0&hide_empty=0&title_li=&orderby=id&order=ASC"); echo '</ul>'; }else{ //如果没有获取顶级分类 } } ?>

7、列表循环、wordpress列表页循环调用标签

<?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <li class=" homebk1-item"> <a href="<?php the_permalink(); ?>"> //链接 <div class="homebk1-img"> <img src="<?php $full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full'); echo $full_image_url[0]; ?>" /> //缩略图(特色图片) </div> <h3><?php the_title();?></h3> //标题方法一 <h3><?php wp_trim_words( get_the_title(), 10 );?></h3> //标题方法二 可限制字数 <p><? the_excerpt(); ?></p> //简介方法一 <p><?php wp_trim_words( get_the_excerpt(), 20 );?></p> //简介方法二 可限制字数 </a> <p><?php the_date_xml()?> </p> </li> <?php endwhile;?> <?php endif; ?>

8、分页列表标签 (方法三:functions添加分页代码

<? posts_nav_link(); ?> // 方法一 官方默认调用方法 <?php if(function_exists('wp_page_numbers')) : wp_page_numbers(); endif; ?> //方法二 需用插件 wp-page-numbers <?php kriesi_pagination($query_string); ?> //方法三:自定义分页代码,可以根据需要更改分页代码-需在functions添加分页代码

wordpress的默认分页标签使用起来比较方便,但是如果想做一些样式上的定制,或者做一些修改就比较麻烦了,如果需要定制分页建议使用第方法三

9、分类栏目自定义字段调用

//$cat 默认为当前分类id seo-title自定义字段 <? $post_id = "category_".$cat; $value = get_field( 'seo-title', $post_id ); echo $value; ?> //输出图片字段 <? $post_id = "category_".$cat; echo get_field('img_ioc',$post_id);?> 案例 <? $post_id = "category_".$cat; ?> <title><?php echo get_field( 'seo-title', $post_id ); ?></title> <meta name="keywords" content="<?php echo get_field( 'seo-keywords', $post_id ); ?>"/> <meta name="description" content="<?php echo get_field( 'seo-description', $post_id ); ?>"/>

原文链接:https://blog.csdn.net/qq_39339179/article/details/119142485?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522171852351316800188561452%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=171852351316800188561452&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-22-119142485-null-null.nonecase&utm_term=wordpress%E4%B8%BB%E9%A2%98

© 版权声明
THE END
喜欢就支持一下吧
点赞12 分享