• w1sh

    (@w1sh)


    I’m basically trying to make my Events, Activities, and Travel Guide Pages contain a Post listing based on the Category.

    Example: When you go to the Events page, it has a listing of all the posts with the Category “Events”, when you go to the Activities, it has a listing of posts with the Category “Activities”, etc.

    I can’t find a plugin that does this. All of them either display all the Posts and organize them by category, or just all of 1 category.

    Any help?

Viewing 1 replies (of 1 total)
  • stvwlf

    (@stvwlf)

    Hi – you don’t need a plugin

    to display one category on a page:
    edit the page.php template in a text editor – not a word processor
    /wp-content/themes/{themename}/page.php

    find the start of the WordPress loop
    ( looks something like this- sometimes on one line)

    <?php if (have_posts()) : ?>
       <?php while (have_posts()) : the_post(); ?>

    add this next code before those lines – add your additional categories, change the category ID codes to the ones on your installation. the text in is_page(‘xxx’) should be the page slug (URL) from your static WordPress page

    <?php
    $cat = '';
    if (is_page('events') {
       $cat = '6';  // the WP category ID code for the events category
    } elseif (is_page('activities') {
       $cat = '11';  // the WP category ID code for the activities category
    }
    
    if ($cat) {
      $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
      query_posts("cat=$cat&amp;paged=$paged");
    } ?>
    
    [loop starts here]   === delete this line - next code is already in page.php
    
    <?php if (have_posts()) : ?>
       <?php while (have_posts()) : the_post(); ?>
Viewing 1 replies (of 1 total)

The topic ‘Display Posts in Categories on Pages (Plugin)?’ is closed to new replies.