Forums

Hot to Make a Page LOAD in Category Posts? (2 posts)

  1. sandman008
    Member
    Posted 2 years ago #

    Hey guys,
    I'm trying to make the pages on my wordpress site pull in the posts from individual categories. I'm using the pages as my navigation scheme.

    So for example on my local events page, I want the most current posts from my local events category to load there. So that ALL my posts appear on the homepage, but the individual categories appear in a dedicated page. i know word press has categories built in to sort out content, but I'd like to have it work a little differently for navigation purposes.

    What I've managed to do so far is have a permalink show up on the pages using the following code:

    <?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); ?>
    " rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></h2>
    <?php endforeach;
    }
    }
    ?>

    what i want to have happen, is have the posts appear on pages the same way it does on my homepage (sorted by category of course). Essentially, each page would have a corresponding category with the same name.

    the URL for my blog is http://www.RUNGOV.org

    Thanks guys

  2. sandman008
    Member
    Posted 2 years ago #

    What i was able to do so far:

    on the RUNGOV.org site, I was able to poke around and find some code that allows for Categories to display in pages, Below is the code:

    <?php get_header(); ?>
    <div class= "leftcontent ">

    <?php
    // page id 21 will get category ID 12 posts, page 16 will get category 32 posts, page 28 will get category 17 posts
    if (is_page('7') ) {
    $cat = array(5);
    } elseif ( is_page('5') ) {
    $cat = array(4);
    } elseif ( is_page('28') ) {
    $cat = array(17);
    } else {
    $cat = '';
    }

    $showposts = -1; // -1 shows all posts
    $do_not_show_stickies = 1; // 0 to show stickies
    $args=array(
    'category__in' => $cat,
    'showposts' => $showposts,
    'caller_get_posts' => $do_not_show_stickies
    );
    $my_query = new WP_Query($args);

    ?>

    <?php if( $my_query->have_posts() ) : ?>

    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <?php
    //necessary to show the tags
    global $wp_query;
    $wp_query->in_the_loop = true;
    ?>
    <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    <h2>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></h2>
    <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>

    <div class="entry">
    <?php the_content('Read the rest of this entry »'); ?>
    </div>

    <p class="postmetadata"><?php the_tags('Tags: ', ', ', '
    '); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
    </div>

    <?php endwhile; ?>

    <?php else : ?>

    <h2 class="center">Not Found</h2>
    <p class="center">Sorry, but you are looking for something that isn't here.</p>
    <?php get_search_form(); ?>

    <?php endif; ?>

    </div>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    What i'm trying to do now, is write a case in the code to NOT display anything if the desired pages arent the current page. if that makes sense

Topic Closed

This topic has been closed to new replies.

About this Topic