WordPress.org

Ready to get started?Download WordPress

Forums

I want to display 6 post from 1 category (13 posts)

  1. TataVostru
    Member
    Posted 4 years ago #

    This is the code? for exclude.... I want to display only last 6 from one category
    I am not so familiar with php...

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php
       if (is_home()) {
          query_posts("cat=-3");
       }
    ?>
    <div class="front_trai">
    <div class="fr">
    <div class="trai">
  2. esmi
    Forum Moderator
    Posted 4 years ago #

    This is the code? for exclude

    Yes. That code will exclude all posts from the catgeory with the id of 3.

    I want to display only last 6 from one category

    That's not what the code above will do.

  3. syncbox
    Member
    Posted 4 years ago #

    Are you wanting to do this on one particular page? Or your homepage only? Per what Esmi said, you probably can't do what you are describing with an exclude parameter... which isn't really for a custom query anyway.

    YOu'd likely have to build a custom query of the category you want your posts from and use showposts= whatever value yo want (6)

    as in this example, which is a SECOND LOOP after the ending the first (defaul) lopp with just the endwhile; statement:

    <?php $my_query = new WP_Query('cat=14&showposts=6'); ?>
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <?php the_excerpt(); ?>
    <p >Read the rest of "<?php the_title(); ?>" in <?php the_category(' &raquo; '); ?></p>
    <p class="postmetadata"><?php edit_post_link('Admin Edit', '', ''); ?></p>
    <?php endwhile; ?>

    and after all the loops, add in ending endif; statement

  4. TataVostru
    Member
    Posted 4 years ago #

    my index looks like this

    <?php get_header(); ?>
    <div class="art-contentLayout">
    <div class="art-content">
    
    <?php include (TEMPLATEPATH . '/rotatingpost.php'); ?>
    <?php include (TEMPLATEPATH . '/altestiri.php'); ?>
    <?php include (TEMPLATEPATH . '/toptrailere.php'); ?>
    <?php include (TEMPLATEPATH . '/boxoffice.php'); ?>
    <?php include (TEMPLATEPATH . '/topactori.php'); ?>
    <?php include (TEMPLATEPATH . '/stiri.php'); ?>
    
    </div>
    <?php include (TEMPLATEPATH . '/sidebar1.php'); ?>
    </div>
    <div class="cleared"></div>
    
    <?php get_footer(); ?>
  5. TataVostru
    Member
    Posted 4 years ago #

    thanks it worke.... if i want to display in random?

  6. TataVostru
    Member
    Posted 4 years ago #

  7. TataVostru
    Member
    Posted 4 years ago #

    if i want to display in trailers.... top Stiky post... not the category ....
    the code now is

    <?php if (have_posts()) : ?>
    <?php $my_query = new WP_Query('cat=3&showposts=6'); ?>
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
  8. TataVostru
    Member
    Posted 4 years ago #

    or displaing 6 post i want by id

  9. syncbox
    Member
    Posted 4 years ago #

    These are completely different requests.

    It looks like you are using includes, which has nothing to do with querying the database for the content (posts and metadata) of a category or categories...

    To get 6 posts from different categories, you'd have to use a get_post() function
    http://codex.wordpress.org/Function_Reference/get_post

    and build an array to output the content as you want it displayed. However, I'd go with the custom query I mentioned above and use different categories for the different 6 things you want to display... particularly if you are trying to display the most recent post in each. The custom query would look like:

    <?php $my_query = new WP_Query('cat=1,2,3,4,5,6&showposts=1'); ?>
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <?php the_excerpt(); ?>
    <p >Read the rest of "<?php the_title(); ?>" in <?php the_category(' &raquo; '); ?></p>
    <p class="postmetadata"><?php edit_post_link('Admin Edit', '', ''); ?></p>
    <?php endwhile; ?>

    That would dislay the latest post from each category (1, 2, 3, 4, 5, 6) which *isn't* the same thing as the last 6 posts from ONE category.

    You have to think about how you structure your content before you design the code to get the content. You *could* make the 6 categories as *sub-categories* of that ONE category... I can't take time to figure out how to merge your intention with your content - but once you have it actually figured out logically, then decide if you wnat 6 posts from 1 cat or 1 post from 6 cats...

    HTH

  10. TataVostru
    Member
    Posted 4 years ago #

    tahnks mann ...you are the best....

    PS: http://trailer-youtube.com/test/categories.png

    I want to display categories upthere... it shows only pages..

    dou you know anny trick?

  11. TataVostru
    Member
    Posted 4 years ago #

    Ps look this too.. syncbox( because you are the best explayner) :)

  12. TataVostru
    Member
    Posted 4 years ago #

  13. TataVostru
    Member
    Posted 4 years ago #

    I want only boxxofice

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.