Forums

maximum amount of posts on index.php (7 posts)

  1. travel-junkie
    Member
    Posted 2 years ago #

    hey,

    i've set up wordpress so that my categories are almost seperate blogs. i've got a photoblog category, some other categories, all being displayed in a sideblog and my main category 'travelogues'.

    to make this work i have excluded all categories, except travelogues, from index.php.

    i don't have that many posts yet, but i recently installed the pagenavi plugin and to try this i set the 'show at most___posts' down to 5. the problem then was that there were only 2 posts shown.

    apparently, when i exclude all those other categories from index.php, their posts still count towards whatever you decided your maximum amount of posts would be.

    is there any way to fix this?

    thanks a lot, guys.
    b

  2. darwishian
    Member
    Posted 2 years ago #

    b,

    I'm not too sure I understood your question properly.

    Do you want to show 5 posts when only 2 posts of that category are available? Or do you only want to show posts from a specific category on your main page even if they are less than 5?

  3. Chris_K
    Administrator
    Posted 2 years ago #

    How are you excluding the categories from the index?

    Are you using something like Category Visibility plugin or manually coding it?

  4. travel-junkie
    Member
    Posted 2 years ago #

    darwishian,
    Do you want to show 5 posts when only 2 posts of that category are available?
    well, this would be impossible, don't you think? my problem has nothing to do with 5 or 2 posts. i was merely writing how i found out about the problem.
    i exclude all but one category from the frontpage, but somehow posts from the excluded categories are still counted towards the maximum amount of posts i set under options->reading. now this messes up the index, cause instead of, say 15 posts only 5 are shown. hope this clears things up :)

    handysolo,
    i manually coded this into the index loop:
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php if (in_category('2') || in_category('3')) continue; ?>
    <div class="postmain" id="post-<?php the_ID(); ?>">
    <!--then the loop continues-->

    thanks, b

  5. Otto42
    Moderator
    Posted 2 years ago #

    Yes, if you use that code, then you will shorten the loop.

    Basically, you're getting 10 posts. Then, you're only displaying the posts of certain categories. It doesn't have any way to know to go back and get more posts because you didn't display some of them.

    A plugin like the Category Visibility one above operates in a different way. Instead of getting 10 posts from all possible ones, it changes the query to get 10 posts from categories you're not excluding. That would be the way to go if you want to exclude categories from displaying in certain places.

  6. travel-junkie
    Member
    Posted 2 years ago #

    otto42,
    thanks for this tip. found a plugin that works perfectly.
    now this brings up another problem (doesn't it always? :). i'm using this code to produce a sideblog on the frontpage:
    <?php rewind_posts(); ?>
    <?php $notDone=true?>
    <?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>
    <?php if (in_category(4) && $notDone || in_category(5) && $notDone) { ?>
    <?php echo $post->post_excerpt ?>
    <!-- title, date, content, etc -->
    <?php $notDone=false ?>
    <?php } ?>
    <?php endforeach; ?>
    <?php endif; ?>

    now there is no sideblog, cause the cat-visibility plugin says there's only the 1 cat allowed on the frontpage. a sideblog plugin won't do though, cause with the ones available you can only post to 1 category, whereas i have 6 sideblog categories. do you have any solution for this too?
    b

  7. Otto42
    Moderator
    Posted 2 years ago #

    Use get_posts for this secondary loop instead of rewind_posts.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.