• Resolved elad-bushari

    (@elad-bushari)


    Hi,

    I’m trying to create a sidebar section on a custom page that will show only posts from a category named the same as the page’s name.

    Example:
    Page’s name = mandarin, side bar shows posts all posts from mandarin category (may be a sub category)

    This is what I have now:
    <?php $recent = new WP_Query(“cat=3&showposts=5”); while($recent->have_posts()) : $recent->the_post();?>
    <?php if( get_post_meta($post->ID, “thumbnail”, true) ): ?>
    ” rel=”bookmark”>
    <?php else: ?>
    ” rel=”bookmark”>
    <?php endif; ?>
    <b>” rel=”bookmark”><?php the_title(); ?></b>
    <?php the_content_limit(200, “”); ?>
    <?php endwhile; ?>

    It shows category #3 only, but I’d like it to be more automated once I create a new page (I use a separate page template for this purpose)

    What should I write instead of the category number?

    Thanks!!!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • This will give you something to play with

    <?php
    if (is_page()) {
      $cat=get_cat_ID($post->post_title); //use page title to get a category ID
      $posts = get_posts ("cat=$cat&showposts=5");
      if ($posts) {
        foreach ($posts as $post):
          setup_postdata($post); ?>
          <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
        <?php endforeach;
      }
    }
    ?>
    Thread Starter elad-bushari

    (@elad-bushari)

    Thanks!!! Works great!!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Pull one category on a page where page name = category name’ is closed to new replies.