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,嘿,伙计们,我有一个代码,它呈现了一个特定类别最近的5篇文章。给你 function postsbycategory() { // the query $the_query = new WP_Query( array( 'category_name' => 'news', 'posts_per_page' => 5 ) ); // The Loop if ( $the_query->have_posts() ) { $string .= '<ul cl

嘿,伙计们,我有一个代码,它呈现了一个特定类别最近的5篇文章。给你

    function postsbycategory() {
// the query
$the_query = new WP_Query( array( 'category_name' => 'news', 'posts_per_page' => 5 ) ); 

// The Loop
if ( $the_query->have_posts() ) {
    $string .= '<ul class="postsbycategory widget_recent_entries">';
    while ( $the_query->have_posts() ) {
        $the_query->the_post();
            if ( has_post_thumbnail() ) {
            $string .= '<li>';
            $string .= '<a href="' . get_the_permalink() .'" rel="bookmark">' . get_the_post_thumbnail($post_id, array( 50, 50) ) . get_the_title() .'</a></li>';
            } else { 
            // if no featured image is found
            $string .= '<li><a href="' . get_the_permalink() .'" rel="bookmark">' . get_the_title() .'</a></li>';
            }
            }
    } else {
    // no posts found
}
$string .= '</ul>';

return $string;
函数postsbycategory(){
//询问
$the_query=new WP_query(数组('category_name'=>'news','posts_per_page'=>5));
//环路
if($the\u query->have\u posts()){
$string.='
    ”; while($the\u query->have\u posts()){ $the_query->the_post(); 如果(具有\u post\u缩略图()){ $string.='
  • '; $string.='
  • '; }否则{ //如果没有找到特征图像 $string.='
  • '; } } }否则{ //没有找到帖子 } $string.='
'; 返回$string;
我所期待的是,上面的代码显示了从1到5个特定类别的最新帖子,但我想显示从2到6个类别的最新帖子。 假设我有一个名为Pizza的类别,在该类别中我有10篇名为Pizza的帖子 职位1 职位2 职位3 邮政4 邮政5 邮政6 邮政7 邮政8 邮政9 10号岗位 所以,若我将上述代码应用到我的主页上,它将显示来自比萨饼类的帖子 职位1 职位2 职位3 邮政4 邮政5 但是我想要这个 职位2 职位3 邮政4 邮政5 邮政6

是的,我希望代码从2开始显示帖子,而不是从1开始显示帖子。那么怎么做呢。 请帮助我,我不是一名网络开发人员。

只需在循环中添加一个计数器($I),并拉取前6篇文章,跳过第一篇使用计数器检查的文章

function postsbycategory() {
// the query
$the_query = new WP_Query( array( 'category_name' => 'news', 'posts_per_page' => 6 ) ); 

$i=1;
// The Loop
if ( $the_query->have_posts() ) {
$string .= '<ul class="postsbycategory widget_recent_entries">';
while ( $the_query->have_posts() ) {
    $the_query->the_post();
    if($i>1){
        if ( has_post_thumbnail() ) {
        $string .= '<li>';
        $string .= '<a href="' . get_the_permalink() .'" rel="bookmark">' . get_the_post_thumbnail($post_id, array( 50, 50) ) . get_the_title() .'</a></li>';
        } else { 
        // if no featured image is found
        $string .= '<li><a href="' . get_the_permalink() .'" rel="bookmark">' . get_the_title() .'</a></li>';
        }
        }
        ++$i;
        }
} else {
// no posts found
}
$string .= '</ul>';

return $string;
}
函数postsbycategory(){
//询问
$the_query=new WP_query(数组('category_name'=>'news','posts_per_page'=>6));
$i=1;
//环路
if($the\u query->have\u posts()){
$string.='
    ”; while($the\u query->have\u posts()){ $the_query->the_post(); 如果($i>1){ 如果(具有\u post\u缩略图()){ $string.='
  • '; $string.='
  • '; }否则{ //如果没有找到特征图像 $string.='
  • '; } } ++$i; } }否则{ //没有找到帖子 } $string.='
'; 返回$string; }
对不起,Funk Doc我不是开发人员,所以请您按照上面所写的内容为我完成这项工作。答案中发布的代码将按照您的要求工作。