The MU forums have moved to

Writting a plugin for the Loop (5 posts)

  1. realsol
    Posted 15 years ago #

    I have edited my current them for my personal site to allow me to have a professional site along with a personal family site by hiding posted depending on certain criteria I have set with a Custom Field.

    Works great. I just add

    include "filename.php"

    as the first line after the standard

    if (have_posts()) : while (have_posts()) : the_post();

    which checks my Custom Field and sends back true or false whether it should be seen or not. If false I send a 'continue' to the while loop if it shouldn't be seen.

    I have 2 questions.

    1. Since I am new to Wordpress, I play around and change themes all the time. I really don't like to edit themes whenever possible. Is it possible to do the above as a plugin? I am not sure how to hook in the the loop. Any examples would be great.

    2. When I hide the post from being shown, the theme I am working on sometimes with display a blank 1st page, and I have to click on Page 2 to see the inlcuded posts. Is there a way when I am going to hide to post to un-increment the counter in the loop so it doesn't give me a blank page? Again, from a plugin if possible.


  2. realsol
    Posted 15 years ago #

    Is this not possible? Anyone?

  3. dsader
    Posted 15 years ago #

    I'm not 100% certain what can be done with custom fields in your specific plugin, and I don't know if 1 specific post_id can be knocked out of the query.
    But, as an example I can change every loop Sitewide to not show "uncategorized" posts in the loop on the front page via this mu-plugin:
    function ds_query_no_uncat_posts($query) {
    return query_posts($query .'&cat=-1');

  4. cafespain
    Posted 15 years ago #

    The easiest (from a programmer point of view) way to see what you can hook into in the loop is to open the file query.php in the wp-includes directory and follow the loop through the code.

    Though you may want to look into the posts filters to exclude the posts with your custom fields from the initial results rather than checking each post in turn.

    The Query Overview page linked to above is a good start, as is Custom Queries -

    Consider looking at other plugins that change the content in the loop for ideas as well. Such as Vent ( )

  5. realsol
    Posted 15 years ago #

    Thanks for the replys. I usuall I was looking for an easy answer. Looks like I need to do a little homework. Editing the theme is not that big of a deal since I am only adding one or in some cases 2 lines of code (all the rest is in the include file). It would be a nice option though.

    Thanks again.

About this Topic