【问题标题】:Wordpress, blog-page dont show blogsWordpress,博客页面不显示博客
【发布时间】:2017-07-26 09:56:51
【问题描述】:

我将 wordpress 与 bootstrap 合并,我想要这样的东西:

1|
 | 2
3| 

我检查是否有帖子(当时有 3 个)。接下来是循环并显示博客......但它显示空框......

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

<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>

【问题讨论】:

    标签: php css wordpress twitter-bootstrap


    【解决方案1】:

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

    修改你的代码:

    <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 变量,那么应该使用它,就像我在上面的代码中显示的那样。

    谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-18
      相关资源
      最近更新 更多