主页 > 建站基础 > wordpress > wordpress

single文件

admin2021-12-22

简介上下文章: ?php previous_post_link(%link); ? ?php next_post_link(%link); ?

作者:
<?php echo get_the_author_meta( 'display_name', $post->post_author ) ?>

上下文章:
<?php previous_post_link('%link'); ?>
<?php next_post_link('%link'); ?>

标签代码:
<?php the_tags('标签: ', ', ', ''); ?> 

相关文章:
<?php
$cats = wp_get_post_categories($post->ID);
if ($cats) {
$args = array(
        'category__in' => array( $cats[0] ),
        'post__not_in' => array( $post->ID ),
        'showposts' => 6,
        'ignore_sticky_posts' => 1
    );
query_posts($args);
 
if (have_posts()) : 
    while (have_posts()) : the_post(); update_post_caches($posts); ?>
 <li><a href='<?php the_permalink(); ?>' rel='bookmark' title='<?php the_title_attribute(); ?>'><?php the_title(); ?></a></li>
<?php endwhile; else : ?>
<li> 暂无相关文章</li>
<?php endif; wp_reset_query(); } ?>

网站名:
<?php bloginfo('name'); ?>

文章摘要:
<?php if (has_excerpt()) {
        echo $description = get_the_excerpt(); 
    }else {
        echo mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 170,"……"); 
    } ?>

分类名(不带链接):
<?php $category = get_the_category(); echo $category[0]->cat_name; ?>


浏览量:
/*显示文章浏览次数*/
function getPostViews($postID){
$count = get_post_meta($postID,'views', true);
if($count==''){
delete_post_meta($postID,'views');
add_post_meta($postID,'views', '0');
return "0";
}
return $count.'';
}
function setPostViews($postID) {
$count = get_post_meta($postID,'views', true);
if($count==''){
$count = 0;
delete_post_meta($postID,'views');
add_post_meta($postID,'views', '0');
}else{
$count++;
update_post_meta($postID,'views', $count);
}
}

<?php setPostViews(get_the_ID()); echo number_format(getPostViews(get_the_ID())); ?>



不同的分类使用不同的single模板:

if ( in_category('info')||in_category('meishi') ) {
include(TEMPLATEPATH . '/single-info.php');
}
else {
include(TEMPLATEPATH . '/single-qiye.php');
}

//info是分类的别名



 

很赞哦! (123)

上一篇:首页

下一篇:标签页 tag.php

文章评论

标签云