Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.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博客第一行第2列第二行第3列_Php_Wordpress_Blogs - Fatal编程技术网

Php Wordpress博客第一行第2列第二行第3列

Php Wordpress博客第一行第2列第二行第3列,php,wordpress,blogs,Php,Wordpress,Blogs,我想使用Bootstrap创建Wordpress归档博客模板 第一行的第一篇文章应该有8列,第二篇文章应该有4列 第二行和连续的行应该有4列的帖子 我相信php计数器将启用此模板。有人知道应该如何编写代码吗 模板示例: 首先使用获取所有帖子来获取帖子,这将返回一个对象数组。然后我会像这样循环浏览帖子: // Get all our posts, and start the counter $postNumber = 0; $args = array( 'posts_per_page' =

我想使用Bootstrap创建Wordpress归档博客模板

第一行的第一篇文章应该有8列,第二篇文章应该有4列

第二行和连续的行应该有4列的帖子

我相信php计数器将启用此模板。有人知道应该如何编写代码吗

模板示例:

首先使用获取所有帖子来获取帖子,这将返回一个对象数组。然后我会像这样循环浏览帖子:

// Get all our posts, and start the counter
$postNumber = 0;
$args = array(
    'posts_per_page' => 8
);
$posts = get_posts($args);
// Loop through each of our posts
foreach ($posts as $post) {
    // If we're at the first post, or just before a post number that is divisible by three then we start a new row
    if (($postNumber == 0) || (($postNumber+1) % 3 == 0)) {
        echo '<div class="row">';
    }
    // Choose the post class based on what number post we are 
    $postClass = '';
    if ($postNumber == 0) {
        $postClass .= "col-md-8";
    } else {
        $postClass .= "col-md-4";
    }
    echo '<div class="'.$postClass.'">';
    // Print the post data...
    echo $postNumber. " " . $postClass;
    echo "</div>";
    // If we are at the second post, or we're just after a post number divisible by three we are at the end of the row
    if (($postNumber == 1) || (($postNumber-1) % 3 == 0)) {
        echo '</div>'; // close row tag
    }
    $postNumber++; // Increment counter
}
//获取我们所有的帖子,然后启动计数器
$postNumber=0;
$args=数组(
“每页帖子数”=>8
);
$posts=get_posts($args);
//循环浏览我们的每个帖子
foreach($posts作为$post){
//如果我们在第一个帖子上,或者就在一个可以被3整除的帖子编号之前,那么我们开始一个新行
如果($postNumber==0)| |($postNumber+1)%3==0)){
回声';
}
//根据我们的职位数量选择职位类别
$postClass='';
如果($postNumber==0){
$postClass.=“col-md-8”;
}否则{
$postClass.=“col-md-4”;
}
回声';
//打印帖子数据。。。
echo$postNumber.“.”$postClass;
回声“;
//如果我们在第二个柱子上,或者我们在一个可以被三整除的柱子数后面,我们就在这一行的末尾
如果(($postNumber==1)| |($postNumber-1)%3==0)){
回显“”;//关闭行标记
}
$postNumber++;//递增计数器
}
这将为您提供如下输出:


显然,您需要根据模板对此进行修改,但这将为您提供一个很好的起点。

首先获取所有帖子以获取帖子,这将返回一个对象数组。然后我会像这样循环浏览帖子:

// Get all our posts, and start the counter
$postNumber = 0;
$args = array(
    'posts_per_page' => 8
);
$posts = get_posts($args);
// Loop through each of our posts
foreach ($posts as $post) {
    // If we're at the first post, or just before a post number that is divisible by three then we start a new row
    if (($postNumber == 0) || (($postNumber+1) % 3 == 0)) {
        echo '<div class="row">';
    }
    // Choose the post class based on what number post we are 
    $postClass = '';
    if ($postNumber == 0) {
        $postClass .= "col-md-8";
    } else {
        $postClass .= "col-md-4";
    }
    echo '<div class="'.$postClass.'">';
    // Print the post data...
    echo $postNumber. " " . $postClass;
    echo "</div>";
    // If we are at the second post, or we're just after a post number divisible by three we are at the end of the row
    if (($postNumber == 1) || (($postNumber-1) % 3 == 0)) {
        echo '</div>'; // close row tag
    }
    $postNumber++; // Increment counter
}
//获取我们所有的帖子,然后启动计数器
$postNumber=0;
$args=数组(
“每页帖子数”=>8
);
$posts=get_posts($args);
//循环浏览我们的每个帖子
foreach($posts作为$post){
//如果我们在第一个帖子上,或者就在一个可以被3整除的帖子编号之前,那么我们开始一个新行
如果($postNumber==0)| |($postNumber+1)%3==0)){
回声';
}
//根据我们的职位数量选择职位类别
$postClass='';
如果($postNumber==0){
$postClass.=“col-md-8”;
}否则{
$postClass.=“col-md-4”;
}
回声';
//打印帖子数据。。。
echo$postNumber.“.”$postClass;
回声“;
//如果我们在第二个柱子上,或者我们在一个可以被三整除的柱子数后面,我们就在这一行的末尾
如果(($postNumber==1)| |($postNumber-1)%3==0)){
回显“”;//关闭行标记
}
$postNumber++;//递增计数器
}
这将为您提供如下输出:


显然,您需要根据模板对其进行修改,但这将为您提供一个很好的起点。

尝试一下并发布您的代码!试试看,然后发布你的代码!感谢James,我将完美地实现此功能James模板显示,如何导入数据、标题和摘录?如果您阅读WP_Post()的codex页面,您可以使用
$Post->Post_Title。还有关于你可以从post对象获得的所有数据的codex的详细信息,以及如何使用
apply_filter
正确处理一些数据谢谢James,工作完美谢谢James我将完美地实现这个James模板显示,你如何提取数据、标题和摘录?如果你阅读WP_post()的codex页面您可以使用
$post->post\u title访问标题等数据。此外,还提供了有关codex的详细信息,其中包括您可以从post对象获取的所有数据,以及如何使用
apply\u filter
正确处理某些数据。谢谢,James,工作非常出色