wordpress 自定义分页符

先在functions.php中设置:

function get_pagenavi( $range = 4 ) {
 global $paged,$wp_query;
 if ( !$max_page ) {
 $max_page = $wp_query->max_num_pages;
 }
 if( $max_page >1 ) { 
 if( !$paged ){
 $paged = 1;
 }
 echo "<li>"; previous_posts_link('上一页');echo"</li>";
 if ( $max_page >$range ) {
 if( $paged <$range ) {
 for( $i = 1; $i <= ($range +1); $i++ ) {
 echo "<li><a href='".get_pagenum_link($i) ."'";
 if($i==$paged) echo " class='current'";echo ">$i</a></li>";
 }
 }elseif($paged >= ($max_page -ceil(($range/2)))){
 for($i = $max_page -$range;$i <= $max_page;$i++){
 echo "<li><a href='".get_pagenum_link($i) ."'";
 if($i==$paged)echo " class='current'";echo ">$i</a></li>";
 }
 }elseif($paged >= $range &&$paged <($max_page -ceil(($range/2)))){
 for($i = ($paged -ceil($range/2));$i <= ($paged +ceil(($range/2)));$i++){
 echo "<li><a href='".get_pagenum_link($i) ."'";if($i==$paged) echo " class='current'";echo ">$i</a></li>";
 }
 }
 }else{
 for($i = 1;$i <= $max_page;$i++){
 echo "<li><a href='".get_pagenum_link($i) ."'";
 if($i==$paged)echo " class='current'";echo ">$i</a></li>";
 }
 }
 echo "<li>";next_posts_link('下一页');echo"</li>"; 
 echo '<li><span>共'.$max_page.'页</span></li>'; 
 }
}

调用:

 <div class="pagination">
 <ul>
 <?php get_pagenavi();?>
 </ul>
 </div>

 

调用特色图片为缩略图

调用特色图片为缩略图:
在functions.php中加入add_theme_support( 'post-thumbnails' );
如果想加入自定义格式加入:
add_image_size( 'one', 215, 140, true ); // one是调用参数名,后面是大小
add_image_size( 'two', 345, 205, true ); // Set thumbnailsize

add_image_size( 'big', 350, 220, true ); // Set thumbnail size

调用:尺寸可以在多媒体后台设置
<?php $full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full'); echo $full_image_url[0]; ?><!--特色图像引用:小尺寸-->
<?php $thumbnail_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail'); echo $thumbnail_image_url[0]; ?><!--特色图像引用:中尺寸-->
<?php $medium_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'medium'); echo $medium_image_url[0]; ?><!--特色图像引用:大尺寸-->
<?php $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large'); echo $large_image_url[0]; ?><!--特色图像引用:自定义尺寸-->
<?php $array_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array(200,200)); echo $array_image_url[0]; ?>array(200,200)来定义图片大小也可以 设置为 'one' 在functions.php中设置自定义图片名。

如果没有图片,指定固定图片

<?php if ( has_post_thumbnail() ) { ?>
    <a href="<?php the_permalink(); ?>" target="_blank" title="<?php the_title(); ?>">
        //特色图片
        <img alt="<?php the_title(); ?>" src="<?php $full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full'); echo $full_image_url[0]; ?>"/>
    </a>
<?php } else {?>
    <a href="<?php the_permalink(); ?>" target="_blank" title="<?php the_title(); ?>">
        //暂无图片
        <img title="<?php the_title(); ?>" src="<?php bloginfo('template_url'); ?>/images/morentu.png" />
    </a>
<?php } ?>