Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在wordpress上,设置类别页面中的自定义帖子数_Php_Wordpress_Post - Fatal编程技术网

Php 在wordpress上,设置类别页面中的自定义帖子数

Php 在wordpress上,设置类别页面中的自定义帖子数,php,wordpress,post,Php,Wordpress,Post,我有一个wordpress网站,在类别10的自定义模板中,我有以下代码: <?php function new_excerpt_length($length) {return 30;} add_filter('excerpt_length', 'new_excerpt_length'); global $post; $args = array( 'numberposts' => 5, 'category' => 10 ); $myposts = get_posts( $args

我有一个wordpress网站,在类别10的自定义模板中,我有以下代码:

<?php
function new_excerpt_length($length) {return 30;} add_filter('excerpt_length', 'new_excerpt_length');
global $post;
$args = array( 'numberposts' => 5, 'category' => 10 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) :  setup_postdata($post); ?>
echo get_the_post_thumbnail($post_id, $size)?></div><div id="eu_post_category">
<h2><a class="roll-link" href="<?php the_permalink(); ?>"><span data-title="<?php the_title(); ?>"><?php the_title(); ?></span></a></h2>
<h6><?php the_excerpt(); ?></h6> 
<?php endforeach; ?>

谢谢

<当你点击new posts/older posts按钮时,获取页码(存储在$paged varible中)并将其传递到参数中

     <?php
        $args = array(
            'paged'            => $paged,
            'category'        => 10,
            'posts_per_page'  => 5,
            'post_status'     => 'publish');
        query_posts($args);
        if ( have_posts() ) {
            while ( have_posts() ) { the_post();
                echo $post->post_title;
            }

       }
   ?>

供参考:

参见
     <?php
        $args = array(
            'paged'            => $paged,
            'category'        => 10,
            'posts_per_page'  => 5,
            'post_status'     => 'publish');
        query_posts($args);
        if ( have_posts() ) {
            while ( have_posts() ) { the_post();
                echo $post->post_title;
            }

       }
   ?>