latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Tag page listing all posts

Home Forums Community Forum Tag page listing all posts

This topic contains 11 replies, has 2 voices. Last updated by  Raam Dev 4 years, 9 months ago.

Topic Author Topic
Posted: Wednesday Mar 14th, 2012 at 1:23 pm #8121
Andy White
Username: 58twelve

Hi

I’m just coming to the end of my first membership site project, and I have to say I totally love S2Member Pro. And now here is the but…

I have it working well for everything except tags. Category views, menus and search results all respect the membership levels in terms of what they display on the listing page – i.e search results only show posts for the logged in member level, menus only show options for the correct member levels and category pages only show allowed categories for a given member level. Great stuff.

Where it has all fallen apart is in the tag. I am allowing the use of tags to give more freedom to sub-categorization of resources, and when I click on a tag and access tag.php I see all posts tagged with that tag, irrespective of membership level restrictions in force through categories. Tags will be pretty freeform, so restricting by specific tags will be impossible.

What I have tried to do was put a filter on before the loop to restrict the view by categories, so any tagged posts shown will have to be from an accessible category. But that didn’t work at all.

It works in so far as a user without sufficient access rights can’t access teh post itself, but they see it listed. I only want the tag archive to show posts that a particular user has the right to view. HOw can I do this without having to restrict by specific tags. Or, indeed, can I do it?

If you need to see it in action I can set you up as a user for each of the 2 membership levels and PM you the details.

Thanks in advance

Andy

Andy

List Of Topic Replies

Viewing 11 replies - 1 through 11 (of 11 total)
Author Replies
Author Replies
Posted: Wednesday Mar 14th, 2012 at 3:10 pm #8149
Raam Dev
Username: Raam
Staff Member

Hi Andy,

The only way I can think of achieving this would be to customize tag.php to retrieve each post’s category before it’s displayed and then checking to see if the current user has access to it (using
is_permitted_by_s2member (); please see Example #4 in Dashboard -› s2Member® -› API / Scripting -› Advanced Query Conditionals). Then if they don’t have access to the post’s category, you don’t display that post in the tag list.

Posted: Wednesday Mar 14th, 2012 at 3:12 pm #8150
Raam Dev
Username: Raam
Staff Member
Awarded Andy the ‘Experienced User’ badge.
Posted: Wednesday Mar 14th, 2012 at 3:38 pm #8152
Andy White
Username: 58twelve

Hi Raam

Thanks so much for helping me out. I couldn’t get that example working – not sure what I was doing wrong, but it got me thinking so I had a dig around and I appear to have come up with something that seems to work as far as my testing is showing so far…

<?php 
if (current_user_can('access_s2member_level1')) {
query_posts('showposts=10&cat=1,6,7,8,9,10,11,12,13,14,15,16'); }
		
elseif (is_user_logged_in()) { 
query_posts('showposts=10&cat=1,6,7,8,9'); }
?>

My knowledge is pretty limited, but I just applied a bit of (what was in my view, at least) logic and it seems to be filtering the tag listing in accordance with membership rights. Does that sound right to you?

Thanks again! I’d be really grateful if you can tell me if that’s a robust solution, or not, or whether I need to rethink as it isn’t as robust as it seems to be.

Andy

Posted: Wednesday Mar 14th, 2012 at 3:42 pm #8153
Andy White
Username: 58twelve

Scratch that. Success was shortlived. ALl that is doing is listing all posts in that category and not showing the tag archive at all :-(

Posted: Wednesday Mar 14th, 2012 at 4:08 pm #8156
Andy White
Username: 58twelve

Right, I am trying another approach, but hitting the same difficulties. I thought that if I allow free tagging but insist that either the ‘Subscriber’ tag or ‘Member’ tag is added then I should be able to restrict the tag archive display based on that, but I am still getting all of the posts listed – even the ones that can’t actually be accessed.

How can I get a post that may have multiple tags, but one of which is ‘Member’ not to show up in the listing on the tag archive page that is seen by a Subscriber?

I’m sure it must be do-able, but the examples in the API/Scripting don’t seem to work for this – although I am probably doing something wrong in applying them.

I tried the example 4 you suggested in the loop and outside the loop (can you tell I was not sure how to apply it :-) ) and nothing happened, and I didn’t know what needed changing from the raw example, or what to change it to if it did.

Any help much appreciated.

thanks

Andy

Posted: Wednesday Mar 14th, 2012 at 4:11 pm #8157
Raam Dev
Username: Raam
Staff Member

Hi Andy,

That’s because your query_posts() function is leaving out the &tag= query parameter. Please see the WordPress Codex Function Reference for query_posts().

If you can’t get that bit of code working, I recommend posting a question on the WordPress.org Support Forums.

Posted: Wednesday Mar 14th, 2012 at 4:37 pm #8161
Andy White
Username: 58twelve

Hi Raam

Did you see my post re trying to filter based on an additional tag of Subscriber or Member. Could that work, and if so, how?

Thanks

Andy

Posted: Wednesday Mar 14th, 2012 at 5:54 pm #8169
Andy White
Username: 58twelve

I think I have done it!! Posting in case I have (it seems to work) and it is useful for someone else…

Using the ‘Member’ tag (this will rely on user discipline to hold-up) I have combined a few things:

Set up a tag.php, tag-subscriber.php and tag-member.php template.

tag.php has the following:

<?php get_header(); ?>

	<?php
	if (current_user_can('access_s2member_level1')) { get_template_part( 'tag', 'member' ); }  
	elseif (is_user_logged_in()) { get_template_part( 'tag', 'subscriber' ); } 
	?>
	
<?php get_footer(); ?>

Then the two other templates contain the loop pulling the content as I want it, but the tag-subscriber.php template has the following:

<?php while ( have_posts() ) : the_post();
if (has_tag('Member') ) continue; 
?>

As far as I can tell, as long as all L1 member resources include the tag ‘Member’ then they will be passed over when the tag archive is generated for a Subscriber. Like I said, the person inputting will have to be disciplined, but from teh testing I have done, it seems to work.

What do you think Raam: am I up another blind alley or may this hold up in the real world?

Thanks

Andy

Posted: Thursday Mar 15th, 2012 at 10:40 am #8241
Raam Dev
Username: Raam
Staff Member

Hi Andy,

Thank you for sharing the code. That looks like it should work! :) Also, adding a tag ‘Member’ to posts that are member-only seems a lot more elegant than trying to reverse-check the post category.

Posted: Thursday Mar 15th, 2012 at 6:39 pm #8294
Andy White
Username: 58twelve

I have asked a couple of people to kick the tag section hard and they confirm it works. Sweet! Thanks for inspiring the thought processes!

Posted: Friday Mar 16th, 2012 at 2:25 pm #8388
Raam Dev
Username: Raam
Staff Member

Thanks for sharing the code here, Andy! :)

Viewing 11 replies - 1 through 11 (of 11 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.