wordpress开发建设常用调用代码

1、获取页面分类列表

<?php query_posts('showposts=6&cat=54'); 
//cat=1为调用ID为1的分类下文章
while(have_posts()) : the_post(); ?>
    <li> 
    <a  href="<?php echo the_permalink() ?>"  title="<?php the_title(); ?>"  ><?php the_title(); ?></a>
<?php the_time('Y-m-d'); ?>
    </li>
<?php endwhile; ?>

2、文章内容页获取上一条、下一条代码

<div class="shangxia">
      <div class="shang"><?php if (get_previous_post()) { previous_post_link('上一条: %link');} else {echo "没有了,已经是最后文章";} ?></div>
      <div class="xia"><?php if (get_next_post()) { next_post_link('下一条: %link');} else {echo "没有了,已经是最新文章";} ?></div>
</div>

3、获取Page分类列表

<?php wp_list_pages('title_li=&sort_column=menu_order&child_of=333'); ?>
获取cat分类列表
<?php wp_list_cats("child_of=" . get_query_var("cat") . "&depth=1&hide_empty=0&orderby=order&child_of=59"); ?>

<!--li开始-->
<?php 
if(get_category_children(get_query_var("cat")) != ""){
wp_list_cats("child_of=" . get_query_var("cat") . "&depth=1&hide_empty=0&orderby=order"); 
//获取当前列表分类

}else{
$catID = get_query_var('cat'); // 当前分类ID

$thisCat = get_category($catID);
$parentCat = get_category($thisCat->parent);

// 输出父分类的链接
//echo get_category_link($parentCat->term_id);
$cat = get_category($parentCat->term_id);
echo '<a href="'.get_category_link($parentCat->term_id).'">';
echo $cat->name;
echo '</a>';
}
?> 
<!--li结束-->

4、根据分类ID获取标题

<?php
    $cat_ID = 72;
    //这里是文章的ID
    $cat_name = get_cat_name($cat_ID);
    echo $cat_name;
    //输出文章的 标题
?>

5、当前子页面的栏目名字和链接调用

<?php  
if($post->post_parent)  
    $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");  
else  
    $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");  
if ($children) 
{  
    echo '<ul>';  
        echo $children;  
    echo '</ul>';  
} ?>  

主题测试文章,只做测试使用。发布者:zhaolou,转转请注明出处:https://www.zhaolou.cc/archives/4235

(0)
zhaolou's avatarzhaolou
上一篇 2025年3月22日 上午10:18
下一篇 2025年3月22日 上午10:21

相关推荐

  • wordpress和shopify的详细区别

    wordPress 和 Shopify 是目前最流行的两大建站平台之一,尤其适用于电商、内容型网站或个人博客。它们各有优势,适合不同需求。 下面我们从功能、适用人群、价格、扩展性、操作难度等方面,来详细比较一下两者的区别。 一、基本定义 🧩 WordPress 👉 重点讨论 WordPress.org,是大多数建站者首选。 🛒 Shopify 二、核心定位区…

    外贸 2025年4月8日
    1.0K00
  • Kadence 与 Astra 对比分析(2025最新版)

    对比维度 Kadence Astra 🌐 官方网站 kadencewp.com wpastra.com 🚀 加载速度 极快(Gutenberg 原生优化) 极快(轻量 HTML 构建) 🎨 设计灵活性 Header/Footer Builder + 内置区块设计(Kadence Blocks) Header/Footer Builder + Elemento…

    外贸 2025年5月14日
    1.7K00
  • WordPress 常用开发中的条件判断标签及开发用法

    平时在wordpress开发项目时,会经常使用到条件判断语句的开发场景。 因为通过条件判断逻辑的应用可以实现我们很多的开发数据处理任务,所以条件判断是非常重要,也是用的比较多的一组开发逻辑。 正常的条件都是判断一个标签或是一个布尔值也或是一个循环的数据调用的结果。不同页面的判断,不同数据类型的判断可以实现我们很多的技术应用。 首页(Front)is_fron…

    外贸 2025年3月22日
    1.0K00
  • 如何用 Semrush + Google Trends + Ahrefs 高效挖掘关键词?

    作为Google SEO中最核心的一步,关键词挖掘不仅关系到流量多少,还决定了你内容能否打入目标用户搜索视野。本文以“xxx”为例,带你实操一遍关键词挖掘与筛选的完整流程。 ✅ Step 1:用 Semrush 查询关键词基础数据(Keyword Overview) 打开 Semrush,在左侧点击【Keyword Overview】,输入你想查询的关键词,…

    google seo 2025年5月14日
    2.0K00
  • 常用的Rank Math SEO 中英文对照

    Basic SEO Add Focus Keyword to the SEO title.Add Focus Keyword to your SEO Meta Description.Use Focus Keyword in the URL.Use Focus Keyword at the beginning of your content.Use Focu…

    google seo 2025年9月10日
    62800

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

联系我们

在线咨询: QQ交谈

邮件:156738051@qq.com

工作时间:周一至周五,9:00-18:00,节假日休息

关注微信