• actually i have read so many posts with no result. i want to show posts only from one category i click. (when i’m in a category page i.e. cat=24, i see only posts from cat id = 24). how to do that ?

Viewing 12 replies - 1 through 12 (of 12 total)
  • It should do that by default. Do you have a link and longer explanation?

    Thread Starter maciek773

    (@maciek773)

    https://cs.elomza.pl/archas/ram/wordpress/?cat=24
    you see there posts from whole website not from category artykly-filozofia.

    If you want to do that elsewhere, you can stick this in the ‘loop’:

    <?php query_posts("cat=X"); ?>

    , where X is the id number of the desired category. You can also use: category_name=blah
    where blah is the name of your desired category.

    Does that work for you?

    Thread Starter maciek773

    (@maciek773)

    no it doesn’t it shows unlimited count of posts prolog i have to stop loading my page.

    How about something like this?

    <?php $posts = get_posts( "category_name=whatever" ); ?>
    <?php if( $posts ) : ?>
    <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
      <div class="post">
    	<h3><a href="<?php echo get_permalink($post->ID); ?>" ><?php echo $post->post_title; ?></a></h3>
    	<?php the_content(); ?>
      </div>
    <?php endforeach; ?>
    <?php endif; ?>
    Thread Starter maciek773

    (@maciek773)

    i wrote:

    <?php get_header(); ?>
    
    <ul>
    
    				<?php $posts = get_posts( "category_name=24" ); ?>
    <?php if( $posts ) : ?>
    <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
     	<li id="post-<?php the_ID(); ?>">
    <h1><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>	<?php the_excerpt_reloaded(60, '<p><a><img><p/>', 'excerpt', TRUE, '<p>Czytaj dalej...</p>', FALSE, 1, TRUE); ?>
    
    				</li>
    <?php endforeach; ?>
    <?php endif; ?>
    
    			</ul>
    
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>

    and doesn’t work properly. look at this: https://cs.elomza.pl/archas/ram/wordpress/?cat=24
    should show nothing, cuz i didn’t add anything in cat 24.

    I’m sorry I think I made a mistake…

    change category_name to category

    and then use the category id number after the =.

    That should work.

    Thread Starter maciek773

    (@maciek773)

    nothing changed

    Thread Starter maciek773

    (@maciek773)

    any1?

    a 2 hour wait doesn’t necessitate a bump. practice some patience, please.

    There is something wrong with your permalinks or your archive.php. Also, you don’t appear to have a 404 which means that whenever you click a page that doesn’t exist, it sends you to an archive of all your posts.
    eg: the following two links take you to the same place: namely your index.php
    https://cs.elomza.pl/archas/ram/wordpress/?cat=24
    https://cs.elomza.pl/archas/ram/wordpress/?cat=2400

    1) Make sure that your permalinks are setup correcly.
    2) Make sure you’re updating archive.php and not archives.php
    3) Let us know what you find out.

    i want to show posts only from one category i click. (when i’m in a category page i.e. cat=24, i see only posts from cat id = 24). how to do that ?

    That was the original question. the original answer holds true – WP already does this by default.

    If you have posts from other categories showing up in the wrong category, then go to “Manage” and select one of the posts that’s not supposed to be in “category 24”. Look to the right of the post. There’s a sidebar where you select what categories you want the post to appear in. Make sure you’ve got the right category selected for the post.

    I would start with that before going into extra coding and extending yourself. If you *have* the right categories selected, and it’s still showing all posts in all categories, I would then suspect either the theme code, or you have a corrupted file somewhere.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘how to show posts only from one cat’ is closed to new replies.