wp,wordpress直接sql取数据,分页

直接sql取数据

require('./wp-blog-header.php');
global $wpdb;
$arr = $wpdb->query("UPDATE $wpdb->posts SET click = $click2 WHERE id = $post_id");

print_r($arr);

根据文章id取内容,取字段

$post_id = $_GET['id'];
$post_content = get_post($post_id)->post_content;
print_r($post_content );

 

取文章附件

$id = $post->ID;
$args = array(
    'post_parent' => $id,
    'post_type' => 'attachment',
    'posts_per_page' => 1,
    'orderby' => 'menu_order',
    'order' => 'ASC',
);
                     
$attachments = get_children($args);

 

一个简单列表分页

\wp-includes\functions.php加入下面方法:

function lingfeng_custom_pagenavi( $custom_query,$range = 4 ) {
    global $paged,$wp_query;
    if ( !$max_page ) {
        $max_page = $custom_query->max_num_pages;
    }
    if( $max_page >1 ) {
        echo "
"; if( !$paged ){ $paged = 1; } if( $paged != 1 ) { echo "首页"; } previous_posts_link('上一页'); if ( $max_page >$range ) { if( $paged <$range ) { for( $i = 1; $i <= ($range +1); $i++ ) { echo "; if($i==$paged) echo " class='current'";echo ">$i"; } }elseif($paged >= ($max_page -ceil(($range/2)))){ for($i = $max_page -$range;$i <= $max_page;$i++){ echo "; if($i==$paged)echo " class='current'";echo ">$i"; } }elseif($paged >= $range &&$paged <($max_page -ceil(($range/2)))){ for($i = ($paged -ceil($range/2));$i <= ($paged +ceil(($range/2)));$i++){ echo "if($i==$paged) echo " class='current'";echo ">$i"; } } }else{ for($i = 1;$i <= $max_page;$i++){ echo "; if($i==$paged)echo " class='current'";echo ">$i"; } } next_posts_link('下一页'); if($paged != $max_page){ echo "尾页"; } echo '共['.$max_page.']页'; echo "
\n"; } }

 

 列表页中调用

    
    class="down_ul clearfix" > php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $para = array( 'posts_per_page' => 15,//每页显示 'paged' => $paged, 'cat'=>285,//所调用分类 );

    $myquery=new WP_Query($para); if($myquery->have_posts()) : while ($myquery->have_posts()) : $myquery->the_post(); ?>
  • php endwhile; endif; // wp_reset_query(); ?>



分页css:

.fenye{text-align:center;padding:20px 0  40px 0;}
.fenye a, .fenye span{color:#999;font-size:16px;margin:0 10px;}
.fenye a.current{color:#f9c03a;}

 

转载于:https://www.cnblogs.com/ximishuier/p/10554966.html

你可能感兴趣的:(wp,wordpress直接sql取数据,分页)