WordPress.org

Ready to get started?Download WordPress

Forums

Show a certain category on home page (10 posts)

  1. hampusjageland
    Member
    Posted 3 years ago #

    Hi all,

    Just wonder if any of you would know how to display only posts belonging to a certain category? My site is http://www.hampusjageland.com/01 and I would like the posts under 'Selected Work' to be displayed on the home page. That's the posts I've catagoriezed as selected-work in my wordpress template.

    Really appreciate your help!
    Cheers,
    H

  2. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

  3. hampusjageland
    Member
    Posted 3 years ago #

    Thanks for your help!
    The only problem is that I use :

    <?php
    if($col++ >= $cols_per_row){
    $col = 0;
    echo '</tr>';
    }
    endwhile;
    ?>

    to pull everything in columns... Maybe there's a way of integrating your information with this??

  4. K-Fella
    Member
    Posted 3 years ago #

  5. hampusjageland
    Member
    Posted 3 years ago #

    Wow, that seem quite full on... I might give it a try. I need to keep the 5 columns so I probably need to look at example 3 or 4. Fingers crossed.

  6. hampusjageland
    Member
    Posted 3 years ago #

    Too tricky for me. Example 3 would be the go but didn't really get it to work, only displayed a blank page, without posts.

    Might just redirect the homepage to the selected work category...

  7. hampusjageland
    Member
    Posted 3 years ago #

    Since I use:

    <?php
        // Get the ID of a given category
        $category_id = get_cat_ID( 'Archive' );
    
        // Get the URL of this category
        $category_link = get_category_link( $category_id );
    ?><br><a href="<?php echo $category_link; ?>" title="Archive" class="a">Archive</a>

    to get to the archive posts so there must be a way of only showing the 'selected-work' posts on the homepage. Just can't be that tricky...

  8. K-Fella
    Member
    Posted 3 years ago #

    http://codex.wordpress.org/Template_Tags/query_posts

    Use:

    // Create a new instance
    $second_query = new WP_Query('category=selected-work');
    
    // The Loop
    while( $second_query->have_posts() ) : $second_query->the_post();
     echo '<li>';
     the_title();
     echo '</li>';
    endwhile;
    
    wp_reset_postdata();
  9. hampusjageland
    Member
    Posted 3 years ago #

    Currently it looks like this (I use image grabber to pull in the images) so I'm not sure where to fit in your code:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Thanks for your help!

  10. hampusjageland
    Member
    Posted 3 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags