简体   繁体   English

WordPress的显示在意甲和循环内的帖子数量?

[英]Wordpress show number of posts within the serie and loop?

I am not sure how to describe my request, which means that I have had a hard time Googling it. 我不确定如何描述我的请求,这意味着我在谷歌搜索时遇到了困难。 Anyway what I am looking for is the following: 无论如何,我正在寻找以下内容:

Lets say I have a archive with 15 posts. 可以说我有15个帖子的存档。 The archive page is restricted to 10 posts per page. 存档页面限制为每页10个帖子。 Now I would like to show on the first page post 1-10 and on the second page post 11-15 . 现在,我想在第一页的post 1-10和第二页的post 11-15 I tried to google it but with no luck. 我试图用谷歌搜索,但是没有运气。 All I did find was a general wp_query post count: 我发现的只是一个一般的wp_query帖子数:

<?php
echo $wp_query->post_count;
?>

I guess it shouldn't be too hard to accomplish correct? 我想完成正确的练习应该不难吗? Anyone who can help me out here? 有人可以在这里帮助我吗? Thanks 谢谢

the thing that you wanted is so easy, wordpress query do this default for you, install wp-pagenavi plugin its show a pagination non the footer and only thing you need to do is set the post limits on 10 in wordpress general setting section. 您想要的事情是如此简单,wordpress查询将为您执行此默认操作,安装wp-pagenavi插件,它会显示分页而不显示页脚,而您唯一需要做的就是在wordpress常规设置部分中将发布限制设置为10。

if this is not what you wanted, so please explain with an example. 如果这不是您想要的,请举例说明。

********** i found out what you mean of this *********** **********我发现了您对这个***********的意思

first you have to get posts_per_page , you can get that value whit usin one of these codes 首先,您必须获取posts_per_page,您可以在以下代码之一中获得该值

$default_posts_per_page = get_option( 'posts_per_page' );

or 要么

global $wp_query;
$total_posts = $wp_query->post_count;

after that you need to know witch page your in , so you can use this code to get that 之后,您需要知道女巫页面in,因此您可以使用此代码来获取该信息。

$current = intval(get_query_var('paged'));

now we need a simple calculate to make the numbers you needed, 现在我们需要一个简单的计算来计算所需的数字,

<?php 

    $ppp = intval(get_option( 'posts_per_page' ));
    $current = intval(get_query_var('paged'));
    $last = $ppp * $current;

    echo 'post from : ' . ( ($last+1) - $ppp). ' to : '.$last;
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM