Here are a few others with some explanations:
Similar Node Title:
To use CCK Field Argument:
To use the results of any CCK Field to group together you must first know what part of the CCK field you want to use. Check out this post Theming a Node in Drupal...The Easy Way. Notice in the above code the portion
This piece of code is what you would change depending on what part of the cck field you wanted to use. In my case I wanted the node id that was placed in the node reference url cck widget.
First up, welcome to DrupalSN, hope you enjoy the site!
Here’s how i’d do it:
1) In the view admin page under arguments click on the User:name argument and scroll down the page where you’ll see some options for that argument under “Block: Configure Argument User: Name”.
2) Under “Action to take if argument is not present” select “Provide default argument” then under “Default argument type” select “PHP code” now we can enter some custom PHP code to get the username from the page URL assuming your username is the second argument in the URL
ie. publications/USERNAME
3) Now in the “PHP argument code” box enter the following PHP:
Again I’m assuming the URL is publications/USERNAME and what we are saying here is if the first URL argument is “publications” and the second URL argument is not blank then use the second argument as the views username argument. 4) You should select “hide view / page not found” in the “Action to take if argument does not validate” under “Validator options” that way views will check the user exists and find the view/block is they don’t have any content.
5) Lastly save the view and assign your block to the publications/USERNAME page.
That should do it, let me know if it works, i loaded up views and tested it so should be fine.
Similar Node Title:
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(arg(1));
return $node->title;
} else {
return FALSE;
}if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(arg(1));
return $node->field_reference[0][nid];
} else {
return FALSE;
}$node->field_reference[0][nid]First up, welcome to DrupalSN, hope you enjoy the site!
Here’s how i’d do it:
1) In the view admin page under arguments click on the User:name argument and scroll down the page where you’ll see some options for that argument under “Block: Configure Argument User: Name”.
2) Under “Action to take if argument is not present” select “Provide default argument” then under “Default argument type” select “PHP code” now we can enter some custom PHP code to get the username from the page URL assuming your username is the second argument in the URL
ie. publications/USERNAME
3) Now in the “PHP argument code” box enter the following PHP:
<?phpif (arg(0) == 'publications' && arg(1) != '') {
return arg(1);
}?>Again I’m assuming the URL is publications/USERNAME and what we are saying here is if the first URL argument is “publications” and the second URL argument is not blank then use the second argument as the views username argument. 4) You should select “hide view / page not found” in the “Action to take if argument does not validate” under “Validator options” that way views will check the user exists and find the view/block is they don’t have any content.
5) Lastly save the view and assign your block to the publications/USERNAME page.
That should do it, let me know if it works, i loaded up views and tested it so should be fine.
<?php
$path = drupal_get_path_alias($_GET['q']); //get alias of URL$path = explode('/', $path); //break path into an array
//user print_r($path); to see what the $path array looks likeif ($path<a href="#fn1615124134d4761bd1fa7a">0</a> == 'publications' && $path<a href="#fn2609386284d4761bd1fab2">1</a> != '') {
return $path<a href="#fn2609386284d4761bd1fab2">1</a>;
}?><?php//check we are on a node page firstif (arg(0) && is_numeric(arg(1))) {
$nid = arg(1);
}?> $path = drupal_get_path_alias($_GET['q']);
$path = explode('/', $path);
if ($path0 == 'communities' && $path1 != '') {
return '$path1';
}Action to take if argument is not present: > phpcode:
$path = drupal_get_path_alias( $_GET[“q”]);
$path = explode(”/”, $path);
return $path1;
$path = drupal_get_path_alias( $_GET[“q”]);
$path = explode(”/”, $path);
return $path1;
No comments:
Post a Comment