0

我有 2 个代码块都试图分别从不同类别中提取一个帖子,但它们都返回同一个帖子 - 确切地说是第二个帖子的内容。这是我的代码...

      <!-- homepage block 1 - START -->
  <? $homepage = get_option('of_homepage') ?>
  <?php query_posts('category_name='.$homepage.'&posts_per_page=1'); ?>
  <?php while (have_posts()) : the_post(); ?>
  <!-- Add your content here -->

  <div id="m2" class="f-ms">
    <div id="m3" class="f-ms">
      <h3 class="subtitlessmaller f-fp f-lp">
        <?php the_title(); ?>
      </h3>
    </div>
    <div id="m4" class="f-ms">
      <p class="whitewider f-fp">
        <?php the_content(); ?>
      </p>
    </div>
  </div>
  <?php endwhile;?>
  <!-- homepage block 1 - END --> 

      <!-- homepage block 2 - START --> 
    <? $homepage2 = get_option('of_homepage2') ?>
    <?php query_posts('category_name='.$homepage2.'&posts_per_page=1'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <!-- Add your content here -->

    <div id="featboxtitle" class="f-ms">
      <p class="f-fp f-lp"><span class="subindex"><?php the_title(); ?></span></p>
    </div>
    <div id="featimage" class="f-ms">
      <p class="f-fp f-lp"><?php the_post_thumbnail(''); ?></p>
    </div>
    <p class="smaller">
    <?php the_content(); ?>
    </p>
    <?php endwhile;?>
    <!-- homepage block 2 - END --> 

我对 Wordpress 完全陌生,所以如果我想做的事情是不可能的,请原谅我

4

1 回答 1

0

我找到了自己的解决方案。我需要为 theme-options.php 文件中的每个帖子分配一个类别,然后从管理面板中的主题选项中选择它们,如下所示......

//Select Category
$options[] = array( "name" => "Select a Category for the first homepage greeting",
                "desc" => "Hit the dropdown and select a category from the listings",
                "id" => $shortname."_homepage",
                "std" => "Select a category:",
                "type" => "select",
                "options" => $of_categories);  

//Select Category
$options[] = array( "name" => "Select a Category for the second homepage block of text",
                "desc" => "Hit the dropdown and select a category from the listings",
                "id" => $shortname."_homepage2",
                "std" => "Select a category:",
                "type" => "select",
                "options" => $of_categories); 
于 2013-06-27T00:38:20.937 回答