热点

wordpress开发建设常用调用代码

发布: 2021年08月18日阅读: 1,480

wordpress 数据调用 query_posts

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>';  
} ?>  

 

 

 

推荐阅读

2022年上海松一国庆节放假安排放假通告1,1332022-09-28

2024年春节放假通知春节放假1,0902024-01-08

wordpress开发建设常用调用代码wordpress1,4802021-08-18

WordPress 常用开发中的条件判断标签及开发用法wordpress5612024-04-09