WordPress.org

Ready to get started?Download WordPress

Forums

Post Limit, Category Filters (25 posts)

  1. Zaaba
    Member
    Posted 9 years ago #

    Not sure what's wrong with the encoding... but the amp;amp bits in the code above shd be substituted with the appropiate ampersand symbol.

  2. Zaaba
    Member
    Posted 9 years ago #

    Yeap, fixed it! Thanks Beel.

  3. nolageek
    Member
    Posted 9 years ago #

    This isn't working for me. What version WP is this for?

  4. Zaaba
    Member
    Posted 9 years ago #

    Its for 1.2 but somehow even I can't get it to work! I'm not too sure why though. Still fixing it...

  5. pvicnan
    Member
    Posted 9 years ago #

    ok... i'm rather lost.. *'.'* _Where_ would I put these codes? When I place them in the index.php, I get an error. Thank you!

  6. Anonymous
    Unregistered
    Posted 9 years ago #

    Thanks for spelling this out, very helpful! My home page uses three seperate cateogories, so I have three of these loops in a row. One change I had to make is to reset the counter at the endof the main foreach loop:
    <?php endforeach; endif; $counter = 1; ?>
    otherwise, it remains set at whereever it arrived at the end of the previous go-round...

  7. pvicnan
    Member
    Posted 9 years ago #

    Okay... I'm still rather confused.. *blush* How would I apply this, in relation to this situation? http://wordpress.org/support/10/6012/

  8. pvicnan
    Member
    Posted 9 years ago #

  9. andrew_h
    Member
    Posted 9 years ago #

    Great stuff Zaaba, this is going to be useful.
    Andrew

  10. pvicnan
    Member
    Posted 9 years ago #

    Hmm.. I am continuously getting an error msg, citing a parse error. Help! I followed the intructions given above..

  11. pvicnan
    Member
    Posted 9 years ago #

    Hmm.. any ideas as to how you implemented this? Perhaps someone who has managed to successfully do this can post their entire loop (did I get it right?) here, so that others (mainly me! =op) can learn? Thank you!

  12. Anonymous
    Unregistered
    Posted 9 years ago #

    I am using this on my homepage and it loops both categories fine, but then when I click on a link to go to the article, everything goes blank. And when I click on links in my menu to go to all posts in a certain category, the first loop goes blank. Any ideas on how to solve this problem?

  13. justinbaeder
    Member
    Posted 9 years ago #

    I'm getting the same problem. My site is Filmnite.com.
    I tried putting the loop code in a separate include file, but I still get the same problem - it works on the main page, but not on the individual pages. I'm using m0d_rewrite to get clean URIs.
    I don't know much about PHP, but my guess is that something is different about the $post and $posts variables so that they have values from elsewhere in the page that interfere with the archive links being displayed properly. Anyone know how to reset them? Thanks!
    Here's the code in my catlinks.php include:

    <!-- Generate links to recent posts/pages
    Instructions:
    1. Change the title below to whatever you want.
    2. Change the # in in_category(#) to whatever category you want to list posts for.
    3. Change the 3 in $counter > "3" to the number of posts you want to display links to.
    4. Copy and paste this loop for each category you want to display, and change the above values as necessary. Note: This does require some server processing overhead, so use it sparingly.
    For further documentation/author info see this thread:
    http://wordpress.org/support/index.php?action=vthread&forum=10&topic=6012&page=0
    -->

  14. Upcoming
    • <!-- category-based link loop -->
      <?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>
      <?php static $counter = 1; if ( $counter > "3" ) { break; } else { if ( in_category(2) && !$single ) { ?>

    • "><?php the_title(); ?>

    • <?php $counter++; } } ?>
      <?php endforeach; endif; $counter = 1; ?>
      <!-- End of category-based link loop -->
  15. Previous
    • <!-- category-based link loop -->
      <?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>
      <?php static $counter = 1; if ( $counter > "3" ) { break; } else { if ( in_category(3) && !$single ) { ?>

    • "><?php the_title(); ?>

    • <?php $counter++; } } ?>
      <?php endforeach; endif; $counter = 1; ?>
      <!-- End of category-based link loop -->

  • Zaaba
    Member
    Posted 9 years ago #

    Anonymous & Justin: From what I know, and correct me if I'm wrong, the reason why links result in blank pages is because:
    1. The loop has not been reset to ONE. If that is the case, loops will break because the loop threshold has been met. Remember to put the revised WP loop end (see above post). I see you have already done this Justin so ignore this point :)
    2. Another reason is the !$single rule has been invoked. You might want to try toggling this on/off by deleting/adding the ! symbol. Remember that the ! results in the NOT logical operator. If you have the the !$single rule in your filter, the loop will NOT SHOW if you are in "single-post" mode (e.g. what happens when you click on a permalink). If you want the loop to show regardless of whether you are in full index mode or single post (permalink) mode then just delete the && !$single rule. Ommitting the ! altogether results in the loop ONLY SHOWING if in single-post mode.
    For example, my site at http://www.truedeath.com has 2 loops: the central blog loop and the photoblog loop. The central blog loop calls all posts BUT from the photoblog category. The photoblog loop at the side calls posts from ONLY the photoblog category and ONLY if NOT in single-post mode ie: only if we're on the main index page else it will be hidden.
    Ah, but this posed a problem: what if the visitor clicks on a permalink of a photo? The index file would not display it because the category filter would filter it out. My solution then was to create another page - photoblog.php which is the exact clone of index.php but with the photoblog category filter reversed so that it would ONLY show posts from the photoblog category. This was the fastest workaround I could come to without uber hacking the index file any further than I had already done above.
    The operating logic above is really quite simple. I guess if you want to have more complex rules you'll have to tinker alot more with the if statements. If its only 1 index file that you want to worry about then perhaps it would be best to come up with many loops (as in MANY loops) with each having its own set of rules. You can set some to only appearing in single-post mode and some in all modes but excluding certain categories. This is probably very cumbersome but I'm sure with much PHP engineering and dilligence you could combine many of those rules and if statements into one single block.
    Might I suggest writing out on a sheet of paper what exactly you want visible at any time and then cater those rules to fit around those permutations. Remember to take note of the ! NOT operator! Good luck!

  • pvicnan
    Member
    Posted 9 years ago #

    Hurrah! I've got it working! Thank you!

  • nsxpower
    Member
    Posted 9 years ago #

    No, you didn't. Click a permalink or comments link.

  • Zaaba
    Member
    Posted 9 years ago #

    Ooh pvicnan, that really is nasty. You might want to check the !$single rule again because nothing is showing up on single-post mode.

  • DominikSchwind
    Member
    Posted 9 years ago #

    I have the same problem here and I think, the problem lies within the $cat=x, that overrides the in_category(x)..

  • Kitten
    Member
    Posted 9 years ago #

    I wrote a plugin for this,
    http://mookitty.co.uk/devblog/category/show-categories/
    I comes with instructions for multiple loops, and will leave alone the category & permalink display of posts.

  • DominikSchwind
    Member
    Posted 9 years ago #

    Thank you very much.. :) Rocking! :)

  • Zaaba
    Member
    Posted 9 years ago #

    Sweet! Will try it out when I get the chance Kitten. Thanks! Finally... a PLUGIN!

  • s_chris
    Member
    Posted 9 years ago #

    hello, my first post here :)
    i've been playing with WP for just a couple of days now.
    i'm using the code posted above to have 3 loops for my 3 categories - first displays a sticky post (using a plugin), second and third (should) display the 5 most recent posts per category.
    in admin-panel i've set the option to display the 10 most recent posts (so it should display 5 per category).
    now the problem is as following:
    if the 10 most recent posts are all in my second category, the third one won't display any posts. increasing the recent-posts-value in the admin-panel would't solve the problem - if i'd set it to lets say 50 posts and all the recent 50 posts are in one category the other one still wouldn't display anything.
    so my questions are:
    can this be solved without having to write custom queries?
    or did anyone experienced the same problem and already found a solution?
    btw, i had a glimpse at kittens plugin but it didn't work the way i wanted (or i have done something wrong).
    maybe someone with similar requirements as myself (always show the last 5 post per category) can tell me if it's working?
    thanks!

  • pvicnan
    Member
    Posted 9 years ago #

    Ookaay.. haha.. i guess i didn't.. I reverted back to the original style sheet for now (after pulling half of my hair out =op) I'll be checking out the plug in..

  • Anonymous
    Unregistered
    Posted 9 years ago #

    The way I solved this was to fill the $posts collection with one author's posts (or category in your case) and fill another collection with the other author's posts. (execute query twice but with "where author =")
    It isn't the most pretty way of fixing this problem, but hey it works ;) You can see the result on http://5dollarshake.com . If you need more detailed explanation, let me know.

  • ludvig87
    Member
    Posted 9 years ago #

    If I put in this code:
    <?php endforeach; endif; ?>
    I would receive a parse error...
    If I let it stay as the original:
    <?php endforeach; else: ?>
    the coding would work..
    Putting in:
    <?php endforeach; endif; $counter = 1; ?>
    wouldn't work either...
    So if you get a parse error, just try and see if it is that part of the code that is causing it...

  • Topic Closed

    This topic has been closed to new replies.

    About this Topic

    Tags

    No tags yet.