WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] link to category depending on current Page (6 posts)

  1. csleh
    Member
    Posted 7 years ago #

    I have a few Pages set up, since the content is fairly static. Let's say a Page has 1 category with multiple posts related to that topic. How can I associate categories to a certain page? For instance if I'm on page B, I need a link to posts 1, 2, 3 and 4 in the X category. Page C would need the same for posts in the Y category.
    Is there a way to associate a Page with a category? Or is there an if/then statement appropriate?

    Many thanks -- I've been searching but think my phrasings must be not quite right to find answers.

  2. rudolf45
    Member
    Posted 7 years ago #

    I don't know if something has been changed recently but normally Pages are not related to categories, in other words: Pages don't have categories.

  3. csleh
    Member
    Posted 7 years ago #

    Perhaps I'm thinking all backwards --

    how might I have links to posts in 1 particular category, but only from 1 particular Page?

    Page A shows links (category apples) posts macintosh, gala, etc.

    Page B shows links (category baking) posts pies, cobblers, etc.

  4. csleh
    Member
    Posted 7 years ago #

    Is it possible to have the loop show something like this:

    -if page=id9, show posts in category2

    I've seen an if is=home statement -- does that work for any page?

    (having a hard time making sense of the documentation. help greatly appreciated!)

  5. csleh
    Member
    Posted 7 years ago #

    I found this, seems to work.
    <?php if ( is_category('2') ) : ?>

      <?php
      $posts = get_posts('category=2');
      foreach($posts as $post) :
      ?>

    • "><?php the_title(); ?>
    • <?php endforeach; ?>

    <?php endif ; ?>

    I'm putting in this in for future reference -- for myself and others who might search with similar terms.

  6. csleh
    Member
    Posted 7 years ago #

    darn something happened. here it is again:

    <?php if ( is_category('2') ) : ?>
    <ul>
    <?php
    $posts = get_posts('category=2');
    foreach($posts as $post) :
    ?>
    <li>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    </li>
    <?php endforeach; ?>
    </ul>
    </li>
    <?php endif ; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags