• Resolved Nowayback

    (@nowayback)


    What I’m trying:
    Creating different pages on the normal page template. I’m trying to edit that page template, so that it reads the page ID and activates a different loop.

    Example: I create a page called ‘Sales’ with the page ID of 59. This activates a loop which reads the category ‘Sales’. See below for the exact code:

    <?php the_post() ?>
    <?php query_posts('category_name=Sales&posts_per_page=5'); ?>
     <?php while (have_posts()) : the_post(); ?>
    <?php the_title() ?>
    <?php the_content() ?>
      <?php endwhile;?>

    Then I create a different page called, for example, ‘Store’ which activates a different loop with posts from the catogery ‘Store’.

    So my question is, how can I write some sort of If Else statement that reads the page ID and activates the loop that belongs to that page?

    Thanks in advance!

Viewing 2 replies - 1 through 2 (of 2 total)
  • <?php
    if( is_page('59') ) $args = 'category_name=Sales&posts_per_page=5');
    elseif( is_page('73) ) $args = 'category_name=Foo&posts_per_page=5');
    query_posts($args);?>
    Thread Starter Nowayback

    (@nowayback)

    Thank you! Although I already figured it out myself =P

    Thanks anyway! ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Loop activated on page ID’ is closed to new replies.