首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Wordpress,博客-页面不显示博客

Wordpress,博客-页面不显示博客
EN

Stack Overflow用户
提问于 2017-03-06 21:42:31
回答 1查看 26关注 0票数 1

我合并了wordpress和bootstrap,我想得到这样的东西:

代码语言:javascript
运行
复制
1|
 | 2
3| 

我检查是否有post (当时有3个)。下一步是循环并显示博客...但它显示的是空盒子。

我做错了什么?或者,也许有更好的方法来做到这一点?

代码语言:javascript
运行
复制
<div class="wrapper">

    <?php
        $rest_query = new WP_Query(array(
            'orderby' => 'post_date',
            'order' => 'DESC',
            'post_type' => array('post'),
            'post_status' => 'publish'
    ));

  if($rest_query->have_posts()):
    ?>

    <?php while($rest_query->have_posts()): $rest_query->the_post(); ?>

    <?php 
        if ($rest_query->current_post == 0)
        { 
            echo '<div class="row">
            <div class="col-md-6">
                <div class="single first-post">
                    <a href="<?php the_permalink(); ?>"><div class="thumb"><?php the_post_thumbnail(); ?></div></a>
                    <div class="content">
                        <a href="<?php the_permalink(); ?>"><h1><?php the_title(); ?></h1></a>
                        <div class="data">
                            <p class="date"><?php echo get_the_date();s ?></p>
                            <p class="social">0 shares / 0 comments</p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="middleLine"></div>
            <div class="col-md-6"></div>
        </div>';
        } 
        elseif ($rest_query->current_post == 1)
        { echo '<div class="row">
            <div class="col-md-6"></div>
            <div class="middleLine"></div>
            <div class="col-md-6">
                <div class="single secound-post">
                        <a href="<?php the_permalink(); ?>"><div class="thumb"><?php the_post_thumbnail(); ?></div></a>
                        <div class="content">
                            <a href="<?php the_permalink(); ?>"><h1><?php the_title(); ?></h1></a>
                            <div class="data">
                                <p class="date"><?php echo get_the_date();s ?></p>
                                <p class="social">0 shares / 0 comments</p>
                            </div>
                        </div>
                </div>
            </div>
        </div>'; } 
    ?>

    <?php endwhile; ?>

    <?php endif; ?>
</div>
EN

回答 1

Stack Overflow用户

发布于 2017-03-06 22:06:53

我认为你的代码在页面中显示时有一些错误。当您使用ECHO时,您不应该在其中使用PHP标记,这就是它在您的情况下不起作用的原因。

修改你的代码:

代码语言:javascript
运行
复制
<div class="wrapper">

<?php
    $rest_query = new WP_Query(array(
        'orderby' => 'post_date',
        'order' => 'DESC',
        'post_type' => array('post'),
        'post_status' => 'publish'
));

if($rest_query->have_posts()):
?>

<?php while($rest_query->have_posts()): $rest_query->the_post(); ?>

<?php 
    if ($rest_query->current_post == 0)
    { 
        echo '<div class="row">
        <div class="col-md-6">
            <div class="single first-post">
                <a href="'.the_permalink().'"><div class="thumb">'.the_post_thumbnail().'</div></a>
                <div class="content">
                    <a href="'.the_permalink().'"><h1>'.the_title().'</h1></a>
                    <div class="data">
                        <p class="date">'.get_the_date().'</p>
                        <p class="social">0 shares / 0 comments</p>
                    </div>
                </div>
            </div>
        </div>
        <div class="middleLine"></div>
        <div class="col-md-6"></div>
    </div>';
    } 
    elseif ($rest_query->current_post == 1)
    { echo '<div class="row">
        <div class="col-md-6"></div>
        <div class="middleLine"></div>
        <div class="col-md-6">
            <div class="single secound-post">
                    <a href="'.the_permalink().'"><div class="thumb">'.the_post_thumbnail().'</div></a>
                    <div class="content">
                        <a href="'.the_permalink().'"><h1>'.the_title().'</h1></a>
                        <div class="data">
                            <p class="date">'.get_the_date().'</p>
                            <p class="social">0 shares / 0 comments</p>
                        </div>
                    </div>
            </div>
        </div>
    </div>'; } 
?>

<?php endwhile; ?>

<?php endif; ?>

注意:如果你想打印任何PHP变量,那么应该使用它,就像我在上面的代码中显示的那样。

谢谢

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42627177

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档