I have a node (node a) with which various other nodes (node b/c/d/e) references.
I can create a view with an argument as the node I'm viewing, (node a), and get a list of the nodes that are referencing that node.
Basically on node a viewing a list of node b-e.
I want to create a views page just for the node references of that node. But how can I pass on the argument to the new page?
Thanks.
Edit: I apologize for the confusing question.
Basically I have a movie node. I have many reviews referencing the movie node.
On the movie node I use argument: content: review_of to get a listing of reviews for that movie.
This is great, but because on the movie node there's only a few reviews, I need a page where I can see all the reviews per that movie. The question is passing on the argument for the movie from the view block (say, 3 reviews for the movie) to a view page (with all the reviews).
Ideally the url for the views page would be: /movies/movie-name/reviews
I have tried this with relationships as in Owen's answer, but was not able to make this work.
If I understand what you're saying, you're wanting to create a Views page that allows you to view nodes associated with a parent node (via a CCK Node Reference field)?
Once you setup your View, you can just pass the nid (or title, or whatever field you choose as your argument), to the URL.
So, assuming you have a Views page setup at: http://yourinstall.com/related-nodes
Just pass the argument in: http://yourinstall.com/related-nodes/5
The above (assuming your relationships / arguments are correct) will show all associated nodes with NID 5.
Here's an image of the views configuration I used.
You'll note the "path" setting on the views is "movies/%/reviews". I had two movies "Movie One" and "Movie Two", with a few reviews on each. You can then use http://yourinstall.com/movies/movie-one/reviews, etc... to see the titles of the reviews.
edit: Ok, so the clarification of the problem is, you have a Views block which displays a list of Reviews specific to a Movie. As well, you'd like the "more..." link to link to a Views page which display all the Reviews specific to that Movie.
This is doable via the Views admin, but does involve a bit of PHP code.
Your Views block can be setup similar to the above Views page.
Override your Views block Arguments (Review Of) Node: Title, and under "Action to take if argument is not present", select "Provide default argument" -> "PHP Code".
The code you use is:
if (arg(0) == 'node' && is_numeric(arg(1) ) ) {
$node = node_load(arg(1) );
return str_replace(' ', '-', strtolower($node->title) );
}
In essence, the Views block acts the same (expects a Movie node title), but will use the code above to try pull the title from the URL (note this works fine with path aliases). The Movie node title is placed into the more link as well (see the above image) in the format "movies/[movie-title]/reviews", which will link to the Views page as expected.
Am I understand this problem correctly?
The real problem is that the "more" link in the block doesn't link to the proper view?
In other words, If your view is "movie_reviews", and on the movie node page you have: movie_reviews->block added on the side, within this movie_reviews->block the "more" link directs visitors to movies/all/reviews ?
Have you considered templating these changes? (manipulating the link within the block to work with the node of the currently being viewed movie node.)
Blocks are very easy to theme.
I can give references on how to implement something like this if I this makes sense for your site.
Related
I'm going to try to explain my project.
I have one section to create on my drupal's site called "Press Room" in this section the users access it via menu item called "Shows". The mainly idea is that the second level of this menu will be created with taxonomy vocabulary called shows and the terms of this are for example:
-Shows(Voclabulary)
-Heartland(term)
-Bulloch Family(term)
And now the next step is create for each one of the terms the next structure:
-About
-Press Materials
-Video
-Fotos
To be more specific I've attach two piece of wireframes of these.
What is the best way to do that?
Thanks!!
[The menu show like that][1]
![The content once you click in the menu][2]
http://i.stack.imgur.com/tijAU.png
http://i.stack.imgur.com/1oifQ.png
I can propose a solution although there are too many options here.
1) Heartland(term) -Bulloch Family(term): there is no need to use taxonomy terms, they can be node types (let's call it "Show" content type).
2) About, Press Materials, Video, Photos and Contact will be 5 node types too. But these will have a reference field to the node types above (Shows).
3) The display page of each Show will be a views that will display the node Show and the content that are referencing this node.
4) Menu can be created by hand (if shows are not too many) or by a views that will show a list of node links.
Examples:
http://ericgilbertsen.com/2013/06/create-related-content-blocks-drupal-7-views-entity-reference
http://www.webomelette.com/related-content-block-views-drupal-7
I am working with a module.
I have a node id. That node id is a page and it has 2 or more view blocks on it. The results of views are lists of nodes with file attachments.
I need to get all the files attached to the nodes outputted by the view on this particular page.
I work in a module file and I can supply the nid of type page where these views sit.
I could not find much help so I decided to ask for what would be the best way to approach this.
I am new to Drupal so I will appreciate a great explanation on how to approach this.
If I understand your question correctly, you need to print the View with arguments set.
Grab the view's machine name and the display id (In Drupal 6 Views 2, hover your mouse pointer on the displays list (Block, Page, etc) and in the URL, you will see something like "block_4" or "page_1". That's the display ID. In D7 Views 3, you can set the display ID in advanced field set in right pane).
If the View's machine name is "my_view" and display id is "block_1",
you can print the view in node.tpl.php or anywhere using the below code.
<?php
print views_embed_view('my_view', 'block_1', array(arg(1)));
?>
arg(1) contains the node ID. If you are putting the code in a node.tpl.php or in a it's variation, arg(1) is always the node ID. If it goes to a page.tpl.php, make sure that arg(1) is numeric at least.
In the View, you will have to add an argument (Contextual filter, in D7 words) to make the View get the argument correctly. You can also set the contextual filter to get the argument automatically from the URL as well.
I wonder if there's a Drupal module that can do this kind of functionality: if i go to home page, it will take me to some subpath within the site. i.e. www.something.com will redirect to www.something.com/product/node/11.
I tried creating an alias and used Path redirect module but for some reason, i can't reach the expanded URL when going to home page. it will display the content of www.something.com/product/node/11 but still using www.something.com.
I'm thinking that this can only be implemented in Apache server, not inside Drupal?
Note that our purpose of doing this feature is whenever a new product is created, we want our home website to point to that (i.e. www.something.com -> www.something.com/product2/home, before www.something.com/product1/home). If this is configurable inside Drupal, the changes would be easier and can be done by a Drupal administrator.
You should be able to go to /admin/settings/site-information and set the Default Front Page at the bottom of the form. That doesn't do a redirect: the home page will BE whatever you set the default to.
Create a new view (Node type) named "frontpage_redirect"
As suggested in answer by Michael D, create and save a view configured to search for your specified criteria:
display: page display, path = frontpage-redirect
pager: 1 item
row style = Fields
fields: Node => Node ID
filters: node type = product
sort: post date desc
Save your new view
At admin/config/system/site-information, set your "Default front page" to the view display path above (frontpage-redirect in my example)
In the view edit screen select "Theme: Information" link in the Page display. Look for the most specific (rightmost) entry under "Field Node: Nid (ID: nid)" - should be something like views-view-field--frontpage-redirect--page-1--nid.tpl.php, but will depend on the view name and display name. Copy the default views template views-view.tpl.php into your theme folder using the filename from 3.
Edit the template and put this code in it:
if (isset($row->nid)) {
drupal_goto('node/' . $row->nid);
}
This way of setting up the redirect lets you drive it from Views, which gives flexibility. When your customer decides in six weeks that they want to feature only the latest red product on the frontpage, you'll be able to update the logic behind the redirect using the views UI. (And you can do it from your phone on the train home!)
You avoid the need to create a custom module (which is easy enough, but does add some complexity) or to move your site logic into .htaccess.
Using the Views module, create a new view that displays one full node, ordered by last created, filtered appropriately, then create a page display in the view. Then follow Graham's instruction to set the site homepage to the view URL.
Another way would be to write a very simple custom module that db-queries for the latest node created of the sort you want, grab the URL to the page, then redirect there using drupal_goto().
There are other ways to do what you want inside Drupal, but I can't think of any that are more direct and simple at the moment...
What you are asking seems wrong. Sorry if I misunderstand some detail, but it seems you should reconsider the problem on a higher level.
If I understand you right, you want to show the page for the latest product as the homepage?
If so, maybe you should turn that into show the latest project page on the homepage. That fits a lot better with the RESTfullness of the web. And with expectations of the users.
The pattern would then be:
GET /products/22 shows product 22
GET /products/23 shows product 23
GET /product/latest shows the last product (in this case, the page would be exactly similar to /products/23)
To achieve that, you can use views module.
On similar lines to Michael D's post, assuming you want to pull the most recently published product from a custom content type called "products," you could put something like this in your settings.php:
function yourtheme_preprocess_page(&$variables) {
$query = db_query("SELECT nid FROM {content_type_products} ORDER BY nid DESC LIMIT 1");
while ($row = db_fetch_object($query)) {
$redirect_nid = $row->nid;
}
if ($variables['is_front'] == 1) drupal_goto("/node/" . $redirect_nid);
}
modify the .htaccess file.
http://drupal.org/node/50322#comment-2456576
http://localhost/rkk/work-type/non-profit
I created a vocabulary and terms under for work-type. and I created some posts...
Then I created a View Block to list my entries, and assigned to a page... everything fine so far.
I display the work-type at entry details page. and I have a link "click to see other non-profit(assigned work type) works". When I click this link, it lists entries assigned to that particular work-type. thats fine, but it displays title/body/readmorelink :/ I need custom view for this page, like I did View Block for listing all posts...
Can I assign custom created View Block to this taxonomy entry list page? the url changes according to work-type, so how do I assign view to changing-url :/
Appreciate helps!! thanks a lot!
UPDATE FOR MORE INFO:
I have a vocabulary (work type), and terms under (corporate, non-profit, etc...)
I have a CCK for "work", and as a field I have select terms of work-type vocabulary.
I have a Custom Views Block to display works in a page (thumb, title, desc, link, etc.).
When I click a work, it goes to particular Work entry details page, I place a link in there "click to see other -term (corporate)- works", etc.
When I click this link, it displays the Work Entries under that particular term. it works fine. but it displays as default look (shown as below), but I need this page same as main works page list (thumb, title, desc, link, etc.) I already have a View for this, but how can assign this View to this dynamic url taxonomy page? I found the module http://drupal.org/project/tvi , but cant make it work.
It should be simpler to overwrite term pages with a view, there's already a pre-configured view for this : taxonomy_term (wich is disabled by default)
I've encountered a Drupal problem: I'm using the Views module for rendering nodes of a kind, based on the user id of it's author (it is a Content Profile actually). I want the view to show the comments for the node, just like in node/%. I could not find any option in views or any relevant module. Am I in the wrong direction and should reorganize stuff for this...?
Any ideas, how can it be done?
Regards,
Laci
Using views is really not the best plan of action. You should instead create a node template in your theme and customize it. If needed you can put some logic in a preprocess function. It requires more coding but will get you where you want.
If you use view node display type
Check in it's settings show comments
if you use view fields display type
Use relationship to comments and select fields you need and theme them
I know this is old request, but I was just struggling with the same issue and came across this post. I thought it'd be helpful to share my solution.
I'm using Drupal 7, with Views 3 and Display Suite.
In your view, choose the display in question.
Under Format, click the first link to the right of 'Show'.
Choose 'Content' (or 'Display Suite' in my case).
Click 'Apply'.
On the next screen, you'll have the option to 'Display comments'. Check this box and save your view.
You should now see the comments displayed under each item in the view.
You could create a second view (with URL e.g. /comments/% where the placeholder will be the node ID, and not the comment ID) that lists comments for a given node, with a contextual filter to only show them based on the NID in the URL.
Then, add that view to the footer (as a 'view area') of the single-node view you've already got.
There's some tweaking required for layout (inline fields etc.) but the basic structure should work.