Forums

[resolved] Displaying 2 different category posts on outside WordPress page (3 posts)

  1. 1800collect
    Member
    Posted 3 years ago #

    So I am trying to get two different categories to display on my homepage. The blog is located in the /results/ folder. And on the home page I want to display two categories in different sections. One is a "portfolio" category and the other is a "news" category. I can easily display one category, but it gets tricky when I try displaying the second category.

    Here is the code I used for the first category:

    <?php
    define('WP_USE_THEMES', false);
    require('results/wp-blog-header.php'); ?>
    
    <?
     if (is_home()) {
    
    	  query_posts('showposts=1&amp;order=desc&amp;cat=18');
       }
    
    if (have_posts()) :
       while (have_posts()) :
          the_post();
    	  ?><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>" id="resultspage"><?php the_title(); ?></a><?
    	  the_content();
       endwhile;
    endif;
    ?>

    I think it's pretty straight forward.

    Now later on in the code I want to display the "news" category. So I do the following:

    <?
    
     if (is_home()) {
    
    	  query_posts('showposts=2&amp;order=desc&amp;cat=21');
       }
    
      if (have_posts()) :
       while (have_posts()) :
          the_post();
    	  ?><li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
    <?php the_title(); ?></a></li><?
       endwhile;
    endif;
    
       ?>

    It still display the first category's post (18) and not the new category. What am I doing wrong? Is this possible?

  2. MichaelH
    Volunteer
    Posted 3 years ago #

    Use a get_posts loop for that 2nd one if necessary:

    http://www.daobydesign.com/blog/2007/07/modifying-wordpress-front-page/

  3. 1800collect
    Member
    Posted 3 years ago #

    It looked like all I had to do was remove this code around my query_posts on my second version.

    if (is_home()) {
     query_posts code here which would work when the if statement removed.
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.