【问题标题】:Dividing post content in 2 columns in Wordpress using bootstrap grid system使用引导网格系统在 Wordpress 中将帖子内容分为 2 列
【发布时间】:2013-08-15 08:57:53
【问题描述】:

我正在尝试创建一个博客页面,我想将帖子分成两列。我正在使用的当前设置是为每一列使用类别。 “类别 1”帖子将显示在左侧栏,“类别 2”帖子将显示在右侧。

我目前有以下代码,其中我使用引导框架提供的网格方法划分了两列。我卡住的地方是 wordpress 一直显示单列页面,如下所示:http://imgur.com/RLeZLVQ

任何想法为什么会发生这种情况?

<div class="container">
<div class="row">
    <div class="span6">
    <?php query_posts('cat=1&showposts=10'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>

     <!-- Display the date (November 16th, 2009 format) and a link to other posts by this posts author. -->

     <small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>


     <!-- Display the Post's content in a div box. -->

     <div class="entry">
       <?php the_content(); ?>
     </div>


     <!-- Display a comma separated list of the Post's Categories. -->

     <p class="postmetadata">Posted in <?php the_category(', '); ?></p>
     </div> <!-- closes the first div box -->

    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>

    <?php endwhile;?>
    </div>

    <div class="span6">
    <?php query_posts('cat=2&showposts=10'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>

     <!-- Display the date (November 16th, 2009 format) and a link to other posts by this posts author. -->

     <small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>


     <!-- Display the Post's content in a div box. -->

     <div class="entry">
       <?php the_content(); ?>
     </div>


     <!-- Display a comma separated list of the Post's Categories. -->

     <p class="postmetadata">Posted in <?php the_category(', '); ?></p>
     </div> <!-- closes the first div box -->

    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>

    <?php endwhile;?>
    </div>
</div>

【问题讨论】:

  • 在第一个 &lt;?php endwhile;?&gt; 之后你有一个额外的 &lt;/div&gt; 这将关闭该行

标签: php html css wordpress twitter-bootstrap


【解决方案1】:

在第一个 &lt;?php endwhile;?&gt; 之后,您有一个额外的 &lt;/div&gt;,这将关闭该行

是的,我很确定这是在做什么

<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>

<?php endwhile;?>
</div>  <----

【讨论】:

  • 解决方案是一个简单的“duh”。将代码放在 single.php(单个帖子页面)而不是 home.php(所有帖子所在的位置)中。无论如何,对于那些感兴趣的人来说,开篇文章中提供的代码是有效的!
【解决方案2】:

解决方案是一个简单的“duh”。将代码放在 single.php(单个帖子页面)而不是 home.php(所有帖子所在的位置)中。无论如何,对于那些感兴趣的人来说,开篇文章中提供的代码是有效的!

这是您必须将完整的代码放置在您的 wordpress 模板的 home.php 中以用于 2 列页面。请注意,您必须在 'cat=' 之后更改数字

<?php query_posts('cat=3&showposts=10'); ?>

您必须使用您希望在每列中拥有的帖子的类别 ID 更改数字。类别 ID 可以在帖子类别选项卡下的 WP 管理屏幕中找到。选择类别并检查 ID 的 URL。

<?php get_header(); ?>
<div class="container">
<div class="row-fluid">
<div class="span6">
  <?php query_posts('cat=3&showposts=10'); ?>

    <?php if ( have_posts() ) : ?>

        <?php while ( have_posts() ) : the_post(); ?>
            <?php get_template_part( 'content', get_post_format() ); ?>
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></h2></a>
        <p>Posted at <em><?php the_time('l, F jS, Y'); ?></em> by <?php the_author(); ?> </p>

        <?php the_content(); ?>

    <?php endwhile; else: ?>
        <p><?php _e('Sorry, this page does not exist.'); ?></p>
    <?php endif; ?>

  </div>

  <div class="span6">
  <?php query_posts('cat=4&showposts=10'); ?>

    <?php if ( have_posts() ) : ?>

        <?php while ( have_posts() ) : the_post(); ?>
            <?php get_template_part( 'content', get_post_format() ); ?>
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></h2></a>
        <p>Posted at <em><?php the_time('l, F jS, Y'); ?></em> by <?php the_author(); ?> </p>

        <?php the_content(); ?>

    <?php endwhile; else: ?>
        <p><?php _e('Sorry, this page does not exist.'); ?></p>
    <?php endif; ?>

  </div>
</div>
</div>

<?php get_footer(); ?>

【讨论】:

  • 您应该发布您使用的代码,以便其他人可以在其他人遇到相同问题的情况下看到差异。然后将其标记为答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-12-19
  • 2012-10-02
  • 2016-01-24
  • 1970-01-01
  • 2016-03-11
  • 1970-01-01
相关资源
最近更新 更多