1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Wordpress : Displaying a single Category on Index.php

Discussion in 'PHP' started by r_shahin, Oct 12, 2008.

  1. #1
    Mornin' folks,
    I'm not sure how I should explain my problem, well, the basic thing is that I wanted to know if I could display a single category posts on Index.php instead of posts from all categories. Now I've seen some answers already been given to this same question but I'm yet to be satisfied, some answers are not clear to me and some I didn't even get a clue what they were talkin about. A post said I could use a small plug-in but I didn't like it. Is there anyway I could use some sort of loop to display a single category? To be more specific, is there anyway I can use a different template for a different category? Now I know it's possible but I need to learn from the scratch so please keep that on your mind. I'm asking about loops cuz I just thought if it was possible then I could just use another file same as INDEX.PHP to display a specific CATEGORY, which I intend to use as a different site page, if you know what I mean. Anyway, hope I'm making sense.
    Here's the list of files that I have in my root directory:
    Index.php
    Archive.php
    Single.php
    Function.php
    comments.php
    header.php
    footer.php
    searchform.php
    sidebar.php


    Thank you~

    To MODS: I'm not sure whether this should be in the PHP forum or HTML forum, so please move it to the right forum if needed.
     
    r_shahin, Oct 12, 2008 IP
  2. Freewebspace

    Freewebspace Notable Member

    Messages:
    6,213
    Likes Received:
    370
    Best Answers:
    0
    Trophy Points:
    275
    #2
    I have made it before but it's custom coding

    like this here
     
    Freewebspace, Oct 12, 2008 IP
  3. r_shahin

    r_shahin Peon

    Messages:
    306
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The link leads o a Tom and Jerry website, I'm not sure how it relates to my question. If it's the site that you made with a specific category posts on the index.php then please post the code here.

    Thank you~
     
    r_shahin, Oct 12, 2008 IP
  4. YIAM

    YIAM Notable Member

    Messages:
    2,480
    Likes Received:
    240
    Best Answers:
    0
    Trophy Points:
    280
    #4
    Following will display posts from a category specified by you.

    
    <?php
    $homepage_catg=1;   // category id of the category 
      
     $postslist = get_posts("numberposts=10&category=$homepage_catg");
     foreach ($postslist as $post) : 
        setup_postdata($post);
     ?> 
    <div class="post" >
    <h2><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <small><?php the_time('F jS, Y') ?>  by <?php the_author() ?> </small>
    
    <div class="entry">
    <?php the_excerpt(); ?>
    </div>
    <p class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
    			</div>
     <?php endforeach; ?>
    
    
    PHP:
     
    YIAM, Oct 12, 2008 IP
    r_shahin likes this.
  5. r_shahin

    r_shahin Peon

    Messages:
    306
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanx YIAM ! Got it now! It worked! Thanx a zillion!
     
    r_shahin, Oct 12, 2008 IP