【问题标题】:wordpress - multiple get_option of category returning same resultwordpress - 返回相同结果的类别的多个 get_option
【发布时间】:2013-06-24 08:04:26
【问题描述】:

我有 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 完全陌生,如果我无法做到,请原谅我

【问题讨论】:

    标签: php wordpress wordpress-theming posts


    【解决方案1】:

    我找到了自己的解决方案。我需要为 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); 
    

    【讨论】:

    • 我要祝贺自己今天对自己有这么好的帮助:-)
    猜你喜欢
    • 2015-07-06
    • 1970-01-01
    • 1970-01-01
    • 2019-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-27
    相关资源
    最近更新 更多