Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.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 - Fatal编程技术网

Php WordPress的额外类别显示在博客页面上

Php WordPress的额外类别显示在博客页面上,php,wordpress,Php,Wordpress,我有以下代码 <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts(array( 'post_type' => 'post', // You can add a custom post type if you like 'paged' => $paged, '

我有以下代码

<?php  
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        query_posts(array(
        'post_type'      => 'post', // You can add a custom post type if you like
        'paged'          => $paged,
        'posts_per_page' => 3,
        'cat_id'=> 5,   
    ));
    if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

我想在我的bog页面上显示id为5的类别。但这显示了其他类别,如4和3。
相似性问题也适用于归档页面。我哪里错了?

请尝试以下代码:

$args = array( 'posts_per_page' => 5, 'offset'=> 1, 'category' => 1 );
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
<li>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endforeach; 
wp_reset_postdata();?>
$args=array('posts\u per\u page'=>5,'offset'=>1,'category'=>1);
$myposts=get_posts($args);
foreach($myposts作为$post):设置_postdata($post);?>

  • 这是我这边的工作

    检查一下,我想这对你有帮助

      <?php 
    $posts = get_posts('category=5&orderby=rand&numberposts=5'); 
    foreach($posts as $post) { 
    ?>
    <a href="<?php the_permalink() ?>" target="_parent"><?php the_title(); ?></a>
    
    <?php } ?>    
    
    
    
    试试这个

    <?php
    $args3 = array(
                            'numberposts' => 1,
                            'cat' => 5,
                            'orderby' => 'date',
                            'order' => 'DESC',
                            'post_type' => 'post',
                            'post_parent' => '',
                            'post_status' => 'publish',
                            'suppress_filters' => true
                        );
    
                        $homepage_post = get_posts($args3);
                        foreach ($homepage_post as $post) : setup_postdata($post);
    
                        // write your code here ...  
    
                        endforeach;
                        wp_reset_postdata();
                        ?>
    
    
    
    --
    谢谢

    我仍然无法得到你的观点这里的偏移量是多少?我已经修改了我的查询帖子,添加了偏移量,但它仍然不适用于我…两个查询都适用于我。。你需要再次检查你的代码。