WordPress.org

Forums

[resolved] Filter Categories On Homepage (User Selectable)? (3 posts)

  1. freefally2k
    Member
    Posted 11 months ago #

    Hi,
    At the moment I am excluding a category using the following code:
    <? php if ( is_home() ) {query_posts($query_string . '&cat=-11'); } ?>

    I want to make it default so the content shows (removing that code) but then the user has an option to hide it, e.g. have a "Don't show content from category 11 link.

    I have tried something along the lines of having index.php and index2.php and having the above code in the index2, however I get the "Not Found" message.

    How could I do this?

  2. karpstrucking
    Member
    Posted 11 months ago #

    You could add a link to the page that includes a URL parameter, like index.php?hide-category-11=true and then check for that parameter in the file:

    <?php
      if ( is_home() && ( 'true' == $_GET['hide-category-11'] ) ) {
        query_posts( $query_string . '&cat=-11' );
      }
    ?>
  3. freefally2k
    Member
    Posted 11 months ago #

    Thanks so much for this karpstrucking, works like a charm :)

Reply

You must log in to post.

About this Topic