用户登录
用户注册

分享至

wordpressget_result wordpress页面分页问题:

  • 作者: 用活着的时间过死后的日子
  • 来源: 51数据库
  • 2020-04-19

有好多朋友都会遇到这样的问题,所以把解决方法写出来.供大家参考.

打开wp-includes/link-template.php 文件,找到

get_page_link(页面链接),get_attachment_link(附件链接),get_year_link(按年存档页面链接),get_month_link(按月存档页面链接),get_day_link(按天存档页面链接),get_pagenum_link(导航数字页面链接),get_feed_link(文章Feed链接),get_post_comments_feed_link(评论Feed链接),get_author_feed_link(按作者文章Feed链接),get_category_feed_link(按分类Feed链接),get_tag_feed_link(按标签Feed链接),get_search_comments_feed_link(搜索评论Feed链接);

在上述函数的最后,都有一个类似的函数:

apply_filters(‘get_pagenum_link’, $result);

而我们需要将相应页面函数修改为:

apply_filters(‘get_pagenum_link’, $result).’/';

这个办法最为直接,将你希望出现反斜杠的页面所对应的函数修改好保存即可。

关于WordPress小工具的问题

呵呵,因为你没有对$wpdb这个全局变量进行声明

如果你需要应用到functions.php里的话,建议建个函数,如:

function get_popular_post(){

global $wpdb; //声明全局变量,这样下面引用时才不会报你那样的错误

$result = $wpdb->get_results(...);

}

wordpress首页如何调用最新文章

第一种方法

WordPress最新文章的调用可以使用一行很简单的模板标签wp_get_archvies来实现. 代码如下:

<?php get_archives(‘postbypost’, 10); ?> (显示10篇最新更新文章)

或

<?php wp_get_archives(‘type=postbypost&limit=20&format=custom’); ?>

后面这个代码显示你博客中最新的20篇文章,其中format=custom这里主要用来自定义这份文章列表的显示样式。具体的参数和使用方法你可以参考官方的使用说明- wp_get_archvies。(fromat=custom也可以不要,默认以UL列表显示文章标题。)

补充: 通过WP的query_posts()函数也能调用最新文章列表, 虽然代码会比较多一点,但可以更好的控制Loop的显示,比如你可以设置是否显示摘要。具体的使用方法也可以查看官方的说明。

第二种方法

调用最新文章:(直接在想要呈现的位置放上以下代码即可)

<?php

$limit = get_option(‘posts_per_page’);

$paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;

query_posts(‘showposts=’ . $limit=7 . ‘&paged=’ . $paged);

$wp_query->is_archive = true; $wp_query->is_home = false;

?>

<?php while(have_posts()) : the_post(); if(!($first_post == $post->ID)) : ?>

<ul>

<li><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute(); ?>”>

<?php the_title(); ?></a></li>

</ul>

<?php endif; endwhile; ?>

第三种方法调用最新文章:

<ul>

<?php $post_query = new WP_Query(‘showposts=10’);

while ($post_query->have_posts()) : $post_query->the_post();

$do_not_duplicate = $post->ID; ?>

<li><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></li>

<?php endwhile;?>

</ul>

第四种方法调用最新文章:

<ul>

<?php $result = $wpdb->get_results(“SELECT ID,post_title FROM $wpdb->posts where post_status=’publish’ and post_type=’post’ ORDER BY ID DESC LIMIT 0 , 10″);

foreach ($result as $post) {

setup_postdata($post);

$postid = $post->ID;

$title = $post->post_title;

?>

<li><a href=”<?php echo get_permalink($postid); ?>” title=”<?php echo $title ?>”><?php echo $title ?></a> </li>

<?php } ?>

</ul>

第四种方法是自己写的,用get_results()函数调用比较快,官网的很多方法都是基于get_results()函数实现的.

以上代码亲测可以使用,如果有问题联系我。

转载请注明:wordpress调用最新文章的四种方法无插件哦 - 前端开发

这种wordpress网站的文章排列方式是怎么实现的

首页,在php里加上相关代码:

<divclass="article-listmobantu"id="article-list">

<?php

$paged=(get_query_var('paged'))?get_query_var('paged'):1;

$args=array(

'caller_get_posts'=>1,

'paged'=>$paged

);

query_posts($args);

while(have_posts()):the_post();

get_template_part('content',get_post_format());

endwhile;wp_reset_query();

?>

</div>

<?php

$next_page=get_next_posts_link('加载更多');

if($next_page)echo'<divclass="article-pagingmobantu">'.$next_page.'</div>';

?>

在js里加上相关代码(前提需要加载了jquery,且网站使用了伪静态分页):

$('.article-paging>a').on('click',function(){//点击实现加载更多,你可以根据自己需要改成下拉自动加载

varnext_url=$(this).attr("href");

varnext_text=$(this).text();

if(next_text=='加载更多'){

$(this).text('加载中...');

$.ajax({

type:'get',

url:next_url+'#article-list',

success:function(data){

result=$(data).find("#article-list.article-item");

next_link=$(data).find(".article-paging>a").attr("href");

//$(this).attr("href",next_url);

if(next_link!=undefined){

$('.article-paging>a').attr("href",next_link);

$('.article-paging>a').text('加载更多');

}else{

$(".article-paging").remove();

}

$(function(){

$("#article-list").append(result.fadeIn(300));

$('.thumb').lazyload({

data_attribute:'src',

placeholder:_BGJ.uri+'/static/img/thumbnail.png',

threshold:400

});

});

$(function(){

if(next_url.indexOf("page")<1){

$("#article-list").html('');

}

$("#article-list").append(result.fadeIn(200));

});

}

});

}

returnfalse;

});

wordpress,高手进

获取总数一般用sql语句“ SELECT count(*)AS n .....”,然后返回n;

或者通过查询全部数据,返回数组,然后count($result)就可以了

如何将wordpress所有文章批量改为已发布状态

global $wpdb; // 筛选所有状态为草稿、定时发布的文章ID $ids = $wpdb->get_col("Select ID from $wpdb->posts where $wpdb->posts.post_type = 'post' and $wpdb->posts.post_status in ('draft','future')"); $result = array(); if ( count($ids) ) : foreach ($ids as $key => $post_id) { $result[$post_id] = $wpdb->update( $wpdb->posts, array('post_status' => 'publish' ), array('ID' => $post_id) ); clean_post_cache( $post_id ); } endif; var_dump($result);代码仅作为参考,可实现将所有状态为草稿、定时发布的文章批量改成已发布状态。这个代码需谨慎执行,建议执行前将数据库备份。

wordpress如何获取当前文章的id,要求写一个函数在function里面调用

<?php

//Theargs

$args=array(

'cat'=>61//这是分类ID,也可以用array给一组ID

);

//TheResult

$naruco=newWP_Query($args);

if($naruco->have_posts()){

//TheLoop

while($naruco->have_posts()):$naruco->the_post();

echo'<li>';

$post_ID=get_the_ID();//这就是文章的ID了。

$post_content=get_the_content();//文章内容,至于怎么截取一定长度的字数,百度一下到处都是啦。

echo'</li>';

endwhile;

}else{

echo'nopostsincurrentcategory!';

}

?>

说的全在注释里了。

WordPress如何使用函数或者方法才能循环获取文章音频

<pre t="code" l="php"><?php

//The args

$args = array(

'cat' => 61 //这是分类ID,也可以用array给一组ID

);

// The Result

$naruco= new WP_Query( $args );

if ( $naruco-> have_posts() ) {

// The Loop

while ( $naruco-> have_posts() ) : $naruco->the_post();

echo '<li>';

$post_ID = get_the_ID(); //这就是文章的ID了。

$post_content = get_the_content(); //文章内容,至于怎么截取一定长度的字数,百度一下到处都是啦。

echo '</li>';

endwhile;

}else {

echo 'no posts in current category!';

}

?> 说的全在注释里了。

转载请注明出处51数据库 » wordpressget_result wordpress页面分页问题:

软件
前端设计
程序设计
Java相关