Is it possible to do this : Create a link in a group's home page that links to a view, which only shows content from that group/subgroup.
Doesn't sound that hard? but....
I tried this by putting a link at the bottom of a group page "click here." I then created a view using the filter "OG: Posts in current group", but when the view is displayed it exits the group and the filter does not work and nothing is shown in the view. I know the exit has occured because the group menu disappears.
So, is there a way of passing a group ID to the view?
I can create content in a group via a link by using /node/ognodeadd?type=tutorial&gids[]=5 (i copied this from the address created by the group menu)
In the address there is ognodeadd (og-node-add) which i assume tells drupal to create the content in that group, can you do a similar thing for just viewing content? Something like ognode/nodetitle?
or is there an easier solution to this?
Comments
Comment #1
SomebodySysop CreditAttribution: SomebodySysop commentedYou have to preface the view url with "og", as in: "og/yourview/yourgroupID".
Here is an export of a view I created that lists just "page" content type nodes from a particuluar group:
A link to "og/ogpages/(GroupID)" will list all "page" nodes in the Group with ID number GroupID.
Comment #2
najibx CreditAttribution: najibx commentedHi,
I wanted to use different theme for each group. How can I pass the argument "built-in" in the theme, page.tpl.php or node.tpl.php or template.php or node-group.tpl.php?
I don't want to Views/Panels2 in the URL to carry out the argument.
Actually, I prefer to use Panel2 instead of just Views. So far I still cannot set the panel at OG homepage after following a few suggestion in the forum. Need help there too.
thanks
Comment #3
ldway CreditAttribution: ldway commentedYOU SAID: "A link to "og/ogpages/(GroupID)" will list all "page" nodes in the Group with ID number GroupID."
ok... For me I have created views built for doing the same. However, These views are meant to be generic for usage in each and every group. For example listing pages or story content created only for the current group.
Now, how in the world does one create a link on a group home page that will pass whatever the current group ID is to the view?
For example... I simply want to create a menu that will display in all groups that will have:
"List pages"
"List Stories"
I then need to have the menu automatically created for the current group the person is viewing and the menu links need to call the view setup for each and only against the current group the user is viewing, So somehow there must be a way to build the links dynamically and pass the current group to the view.
I have my views filtered for current group. However, simply calling a view with a standard link takes the person away from the group home page (All the create menu links are gone). I want the person to stay in the group when viewing a view I created.
How does everyone accomplish this?
Comment #4
moshe weitzman CreditAttribution: moshe weitzman commentedYou have to write some custom code for those links. Your code will call og_get_group_context() to get a $group_node object and that contains the $group_node->nid integer which you will in the link in order to get to the right page.
Comment #5
ldway CreditAttribution: ldway commentedThanks for overview Moshe...
Finally got it all figured out and working. Thanks again for pointing me the right direction!
--Dave
Comment #6
henns20 CreditAttribution: henns20 commentedsorry i don't want to take this conversation backwords but i am confused...
it seems like this thread speaks to the issue that i submitted http://drupal.org/node/200375.
couple of questions- i guess there is no solution to use views (form/interface) to try to get a page view of a block (i am using panels for a homepage on og)....you would need custom code for it sounds like.....
moshe or dnosker is there any way you can provide a snippet on this? i am not to sure how to do it---or if you can point me to something similar so i can get an idea of how it is formed. ..
moshe i noticed you lived in philly for a while - can you help a philly brother out:) (saw your post in philly drupal grps).....thanks again ---jamie
Comment #7
gracearoha CreditAttribution: gracearoha commentedDave,
I have also been trying to figure out how to create this same type of link.
Could you share the code that you used, please?
Comment #8
j_orbin CreditAttribution: j_orbin commentedI would also be interested in this code...
Thanks-
Jim
Comment #9
ldway CreditAttribution: ldway commentedOk, I will do my best to explain exactly what I did, I will take you step-by-step and try to leave nothing out. Pardon for the length of this!...
First you need to understand my use case which may be different than what you are trying to do... In my case, I wanted the following:
1... Have some views that ALL groups will want to use for content that is specific to each group. In other words, while the content created may be specific and viewable only in each group, the contents types available are all the same. i.e. stories, audio, or a page, etc..
2... Based off of the above, I want the same menu for all the views to be on each group page.
3... When a user clicks on a views link in a menu, only the posts for that content type and group are visible.
4.. And finally, when in the view, the user is still in the group without losing all the normal menu's and such of the original group.
So, here is my recipe and steps for all this. Perhaps this all can be done differently but this works for my use case...
-------------------------
1... Creating the Views:
-------------------------
In order for all this to work correctly and have the view stay within the group without leaving the group and original group menu's, etc. you must make your views special for og.
(A) Make a view for each content type you will be supporting in all groups. For this example I will make a view for story content:
... For the View Name Field call it "OGStories"
... Check the box "Provide Page View"
... For the URL field make it "og/ogstories" (IMPORTANT, you must start the url out with "og" or this will not keep you in the group when the view is run!
... For my example view type is "Table View"
... "Title" anything you like. "Story Listing"
... "Use Pager" is checked
... "Breadcrumb Trail should not include home" checked. This is because the home link will be your home page and not the og page if the user clicks it!
... "Nodes Per Page" whatever you want. Mine is at 30.
... under the "Empty Text" field "There are no Stories in this group"
FIELDS:
... Create your fields. I have Title as link, Node Created Time, Node updated time.
ARGUMENTS:
... Add Argument of "OG: Group Nid(s), Set the default to "Page Not Found" put in the title field "%1"
FILTERS:
... Add a filter for "Node: Type". Operator set to "Is One Of" and the value "Story".
... Add a filter for "OG: Posts in current group" Operator set to "Is Equal To" and value "Current Group"
SAVE THE VIEW.
-------------------------
2... MAKING THE MENU TO CALL THE VIEW IN EACH GROUP
-------------------------
... Make a new block.
... In the block description put something like "Group Content"
... Put the same thing in Block Title.
... In the Block Body you will put the following php code. Make sure that you set the Input Format for the Block Body to "PHP Code"
PHP CODE:
-------------------------------------
NOTES:
... You can add other items to this block by following the same format as above (from the li to the end /li Then just set the correct names and views for each item.
... If your wondering why I check for the module og to exist: This is because if you do not do this and later want to disable og (For upgrading, etc) you will have a very big problem. The php code you put into this block will try and run anyways even though og is not enabled and the function "og_get_group_context()" will return a big error for you on your site. (In my case a blank white screen with no way back into the site unless I hand reset og back to being enabled in mysql.)
Block Page specific visibility settings:
You need to provide this to force your menu block to only display on the OG pages and not on the rest of your site.
... Click the radio button "Show if the following PHP code returns TRUE (PHP-mode, experts only)."
... Enter the following code in the Pages: box...
PHP CODE:
----------------------------------------
ENABLE THE BLOCK!
That should do it! Hopefully I left nothing out and all will work for you! :)
You should now have the same menu that appears only while inside of a group for your views and the link on the menu is automatically created for passing the correct GID to the view. Also, your view will stay inside of the group. And last but not least this shows you how to finally have view listings of each separate content type. i.e. creating separate listing for all stories, books, audio, etc that is posted inside of the group.
Hope this helps!
P.S... Please pardon the fact that this was long as I am not the best as far as writing instructions.
-- Dave
Comment #10
ldway CreditAttribution: ldway commentedAlmost forgot to mention...
Please let me know if these instructions are clear enough and everything works as advertised. I will eventually put this in the Drupal Handbook under the How-To section once I am sure it is at a readable and understandable state.
Thanks,
-- Dave
Comment #11
j_orbin CreditAttribution: j_orbin commentedDave -
Brilliant, absolutely brilliant! Thank you very much for your complete explanation. I am going to implement this as soon as possible and I'll let you know how I get on.
Thanks-
Jim
Comment #12
henns20 CreditAttribution: henns20 commentedSweet Ginger Brown! it worked on first go:) <---flamingo kid reference
your post has handbook written all over it....great post!....it was a great work around for not being able to use the more link for panels blocks on OG....The only thing i did different was to use the code to create an inline list above the panels....instead of creating the block....again thanks ... your post is a great representation of the strength of the Drupal community:)
jamie
Comment #13
ldway CreditAttribution: ldway commentedGlad to see it helped ya Jamie...
One thing I might mention is that using the code for making the menu blocks, with a few little changes you can use the same idea for creating a control panel at the top of all your group pages. For example, you could have icons at the top of every page on groups that represent your section listings such as stories, books, blogs, etc. All you have to do is in the header section of each view put your code for your icons and the links will be created automatically. You could make them different for each view. The point is that you really can do a lot using this type of basic code to make your group pages look good with all the links and views you need. And this really shows how powerful Drupal really is. ;)
Comment #14
henns20 CreditAttribution: henns20 commentedya it was great
I have used the header section before....Now when you say
Do you mean PHP code or CSS HTML code? I am trying to picture it
Jamie
Comment #15
ldway CreditAttribution: ldway commentedI was talking about adding php code to the header section of each view. For example, say you wanted a control panel at the top of each view to display some small pictures that link to other pages within the group. Perhaps another view. So, you could using the exact same php code do something like this....
PHP CODE:
Notice how the only thing that was changed from the code before is what is in the $output section. All that was done is having an picture displayed that linked to another view and again the gid was automatically created.
Hope that all made sense!
Comment #16
SomebodySysop CreditAttribution: SomebodySysop commentedThat's not all you can use that views header for. Before dnosker came along with the cool code to create the block, the following is what I put into the view "header" and "empty" fields in order to display the group content on the home page:
Now, adding on to dnosker's code, I have a place to put that link to the group home page that will always be present. Am I the only one bummed out by the fact that there's no Group Home Page link on the Group navigation menu?
Comment #17
ldway CreditAttribution: ldway commentedThat was some great code to share! Loved it!
You Wrote:
"Am I the only one bummed out by the fact that there's no Group Home Page link on the Group navigation menu?"
Yes! And that is just one of the reasons I ended up getting rid of Group Navigation Menu and replacing it with my own using the techniques above...
While we are all in the mood for sharing tips and tricks, here is another little thing I have done...
NOTE: I don't want to get off topic too much but the following is kind of a reverse of this thread which has some merit to mention. i.e. "create a link on NON OG pages that links to a users OG home page"
What I needed:
1... A menu on non group (normal site) pages that would have "My Group". This would be for the users Main group they wanted to be identified with.
2... Make it so that when a user logs into the system, they are taken to their main group home page.
So here is how I accomplished this. (Might be easier ways to do this but this works for me)
----------------
Main Group ID
----------------
This was pretty simple. I just added a field to profiles. "main_group_id". Then each user can simply have the node ID of their main group. Example: Main Group: 1325
----------------
For the menu:
---------------
I made a block that displays a few important items for users. This includes a log off link and a few other items. Most important is the link to the members main group page...
Block Description: Member Menu
Block Title: Member Menu
In the Block body goes my PHP CODE:
That takes care of having a little custom menu for the user that contains a link to their main group.
Now for the auto login to take them to that main group...
I simply use the "Login destination" module and in the settings to specify where exactly the user should be redirected upon login, I put the following
PHP CODE
NOTE: the "Login destination" module does not allow putting opening ?php and ending ?> ... I just put that here to auto highlight the block of code.
And there you have it! There is my little contribution for today. :)
-- Dave
Comment #18
henns20 CreditAttribution: henns20 commentedawesome!!!.... man this really helps in getting to next level of practical php--- great stuff - i am going to work through this ...this weekend- kudos for the thorough explanations
Comment #19
gracearoha CreditAttribution: gracearoha commentedExcellent instructions, Dave! Thanks so much for sharing that valuable snippet :)
Comment #20
Steel Rat CreditAttribution: Steel Rat commentedThis would be fantastic if only I could get the Arguments section to allow me to add arguments. It's been really frustrating with the Views module that sometimes it doesn't give the appropriate options in the different sections. e.g. sometimes I can't add fields because there are no options to add them, other times I can't add arguments or filters, the forms just don't appear. AAAARRRRGGGGHHH!!
Comment #21
bjacob CreditAttribution: bjacob commentedI think I just need some more hints to understand the concept. Maybe you can help me. What did I do:
As you can see I've done something... for sure something wrong. What am I missing? Can anyone help me please?
Comment #22
WISEOZ CreditAttribution: WISEOZ commentedI noticed just one limitation with the appending the view URL with "og" method. Some of the OG views I created are set up to create tabs on the OG home page using the "node/$group/custom" approach, which is explained under the URL field on the View form. Changing this to "og/node/$group/custom" or "og/$group/custom" simply sends the user back to the main OG directory. If anyone knows of a means of keeping the tabs while also having the "More" connect correctly through Panels, I'd be interested in knowing.
On a related topic, I'm also looking for a means of placing the "Create Story", "Create Page", etc links in the header or footer of a view while also obeying the arguments it sends.
Comment #23
najibx CreditAttribution: najibx commentedWe used OG and Domain module for our Malaysia Golf Portal.
We really need to improve the interface to something like myspace/facebook group interface. Currently just simply use the default view.
would like to try with panel2, views & OG.
Comment #24
henns20 CreditAttribution: henns20 commentedyou know that you can do that now - with a little tweaking ---it is not a perfect solution but i have - just use node-groups.tpl.php to insert the panel page.....if you would like i can post the post the link - to the discussion on it....plus Moshe weitzman said that they is OG-panels module out there but I haven't seen it yet...may be he meant it was drupal 6
Comment #25
WISEOZ CreditAttribution: WISEOZ commentedYes, please post it!
Comment #26
henns20 CreditAttribution: henns20 commentedhttp://drupal.org/node/173473 first one
http://drupal.org/node/166119 this is the one that completses the first
Comment #27
moshe weitzman CreditAttribution: moshe weitzman commentedComment #28
Anonymous (not verified) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #29
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedsubscribing
Comment #30
scedwar CreditAttribution: scedwar commentedsubscribing
Comment #31
scedwar CreditAttribution: scedwar commentedTo create a link to create content in the group, or a view header just do:
We have also used nice tricks to alert users to the fact that they are an admin for a group in the view header. Alternatively, that they haven't posted any content in the group that would show in that view (put this in the empty text for the view, modify for the header etc):
Comment #32
Rosamunda CreditAttribution: Rosamunda commentedGenius. Just genius.
Thanks, many, many, MANY THANKS Dave!!!
Your explanation was clean, clear, and effective. It works like a charm.
Thanks!!
Rosamunda
Comment #33
Lioz CreditAttribution: Lioz commentedgreat tutorial!
just one question: what about breadcrumbs?
when i'm on a grooup post i correctly see: "groups>group>"
when i click on the stories i lost the group context (i see only "groups")
i think that i should see "groups>group>stories"
what do you think?
Comment #34
scedwar CreditAttribution: scedwar commentedBreadcrumbs are a nightmare with views. We solved the problem for nodes with the custom breadcrumbs module, however, for the views we are still working on it! If anyone can suggest a link, I'd be very grateful, but this discussion in the Custom Breadcrumbs issue queue suggests nobody has it yet: http://drupal.org/node/215475
Comment #35
ln282 CreditAttribution: ln282 commentedSubscribing.
Comment #36
daniel-san CreditAttribution: daniel-san commentedThanks for posting this. Very applicable to a project I am working and that I've been battling with understanding how to make it work. So, so thankful!!!
- Dan
Comment #37
daniel-san CreditAttribution: daniel-san commentedChanged title back to original. Sorry about that.
Comment #38
izmeez CreditAttribution: izmeez commentedsubscribing
Comment #39
pyxio CreditAttribution: pyxio commentedThis is some excellent stuff. Thanks for sharing the recipe ldway. While on the subject of custom menus, you have shown us how to link to new pages of a content type. How about the link format for pages already generated by og itself? I'd like to throw away the og menu completely. Most specifically, I'm interested in the link format for the group's homepage, the invitation page, the forum page and the members page. I'd like to mix these into my menu for custom contact I created using your recipe above. Thank you very much for the help! Cheers, Kevin
Comment #40
lelizondo CreditAttribution: lelizondo commentedI just want to add that it is not necessary to set the views path to og/something/%.. I use groups/%/stories and then the pathauto for stories is something like groups/[group-id]/stories/[nid]
This way is easier to set the breadcrumb using the path.
Comment #41
izmeez CreditAttribution: izmeez commentedsubscribe
Comment #42
morbiD CreditAttribution: morbiD commentedThe solution in #9 looks like it almost exactly covers what I want to do but I have an additional issue which I'm unsure about.
I am using the subdomain module to assign each organic group to it's own subdomain i.e. to get to group1 you go to group1.example.com and to get to group2 you go to group2.example.com.
As this thread has discussed, I would like views for listing each content type within the current group, but I would preferably like to get to them via links like group1.example.com/news, group1.example.com/letters and group1.example.com/events.
However, from #9:
This makes it sound like what I'm trying to achieve is impossible. Any ideas?
Comment #43
ln282 CreditAttribution: ln282 commentedThis thread has been very helpful to me. I'm using the solution in #9, but wanted the menu to only be seen by group members, and have non-members see a link to the group membership request page instead.
To do this, I added:
if (og_is_group_member($gid)) {
above "$output .= ... "
and then above "print $output", added:
It seems like a simple thing in retrospect, but it took me a while to get here, so I thought I might save a fellow newb some trouble.
Comment #44
riddhi_uppal CreditAttribution: riddhi_uppal commentedAs specified in #9 to use the filter i.e. Add a filter for "OG: Posts in current group" Operator set to "Is Equal To" and value "Current Group" is not working for me. When I select this filter then it not shows anything to select for "equal to" , its rather give option for expose.
We are working in Drupal 6.x
Kindly suggest.
Comment #45
lias CreditAttribution: lias commentedAwesome, this is exactly what I'd been looking for! Thanks Dave for the great instructions.
Edit 071310:
One more thing you can add to your block of group pages is a link to the group homepage (Drupal 5.x):
Comment #46
ivan011 CreditAttribution: ivan011 commentedHi, I'm new into Drupal (and php) world and for sometime I was struggling with one issue...I used solution #9 and it works ok. Links in menu are in form http://mysite/og/ogstories/$gid , and if I understand $gid is id number of a group. But is it possible (I suppose it's possible) to have group name within link instead of id number of a group. So instead of http://mysite/og/ogstories/123 to have ie http://mysite/og/ogstories/group_name. Also, is it possible to have something else then "/og/" within link?
Thanks (and thanks for earlier posted solutions)
Comment #47
Drake CreditAttribution: Drake commentedsubscribed
Comment #48
greta_drupal CreditAttribution: greta_drupal commentedsubscribed
Comment #49
drunkencelt CreditAttribution: drunkencelt commentedHere is the code I have used to get this functionality to work in Drupal 7 based on #9.
You will note the function that returns the Group ID (gid) has changed for D7. I have also added in $base_url to the outputted link so you will not have to manually update your links in the event your site URL changes, for example moving from localhost to production etc.
My views are embedded in a node (view field) hence the node id in the url otherwise everything else is the same.
I should also add that you will not need the second part of the PHP provided to control visibility if you use a node to display your views (view field module) as you can limit the display to a specific content type as part of D7 core.
Hope this helps.
Comment #50
namita21 CreditAttribution: namita21 commented@ drunkencelt - I tried using above code in one of the view of the list of all the pages under a group in header section and I am getting below error:
Parse error: syntax error, unexpected T_STRING in /var/www/html/modules/php/php.module(80) : eval()'d code on line 8
is it related to the code???
I am not really sure what I am missing here, any help is appreciable.
Comment #51
namita21 CreditAttribution: namita21 commentedComment #52
lias CreditAttribution: lias commentedHi, here's the view I use in Drupal 7x24 to display the name of the group in a block as well as a block that displays contact information.
Please note that the fields are specific to my install, you can remove once you've imported. I'm using the latest views and og modules.