WordPress.org

Forums

let user toggle post visibility by category oder tag (4 posts)

  1. bootsmaat
    Member
    Posted 7 years ago #

    Ok, I have a tricky problem here and could use some help.

    I'd like to give the user the ability to toggle posts of a certain category as visible or not. That is, on the index page, on single post pages, in the archives, and in searches.

    For example, there would be three checkboxes at the top of the page labeled business, politics, and sports.

    By checking or unchecking the checkboxes the user chooses what content is displayed.

    Business, politics, and sports would refer to categories or, if that makes it any easier, to tags.

    The navigation links (previous / next page) change accordingly: If business gets unchecked, the navigation must not link to a post that has been filed under business. This is actually the most important feature to me as I only display one post at a time anyway.

    The user's choice must be maintained as he navigates on the site, i.e. clicks links etc.

    I know that there are several plugins out there which give the admin the ability to toggle the visibility of posts of certain categories (like Category Visibility Plugin). But they don't let the user do it.

    Is there a way to hack the php code to do this? Any ideas?
    I'm currently using WordPress 2.2 but I'll upgrade to version 2.3 sooner or later.

    Thanks!

  2. Ivovic
    Member
    Posted 7 years ago #

    I think you'll find that this is what clicking category links is for.

    Once you click on a category link, your <pre .. next> links are only active within that category.

    You just need to make it more obvious that people should be clicking on the category links to filter the posts.

    your alternative is to look into setting cookies, and retrieving them for use in category exclusion queries... which seems like a lot of work considering you already have the functionality

  3. bootsmaat
    Member
    Posted 7 years ago #

    Thanks, Ivovic. The problem is that I want users to be able to see posts filed under several categories or tags at a time. As far as I know, this cannot be done with category links.

    An example: Be default, business, politics, and sports are visible. The user should be able to turn off business posts. The remaining posts are those filed under politics and sports. With category links I can only display posts filed either under politics or under sports.

    That is why I am afraid we have to go into the php code / mysql queries here. It's just that I'm not sure how to do it exactly.

  4. Ivovic
    Member
    Posted 7 years ago #

    I see your issue... and I understand your reluctance to just leave it up to the user to read all the politics posts first, then browse over to sports.

    This will require some custom PHP work, as I'm inclined to think your request isn't a common one (though I've been wrong before).

    You'll need to do something like:

    • provide a preference form to select categories
    • save the preferences as cookies
    • retrieve those cookies prior to displaying The Loop
    • Use the retrieved values to modify the query in the loop to exclude, or conversely include the chosen categories

    It actually doesn't sound like all that much work, really (famous last words, lol).

Topic Closed

This topic has been closed to new replies.

About this Topic