Drupal node 2-page content split - php

My employer requires certain pages on the website have a two page feature.
What this means is that some default content show up on the node_view page as normal but the second part should show up when a link is clicked.
This will be easy if I could do this across multiple nodes but the requirement is for all the data to be stored in one node but displayed across two pages.
I hacked together the following code:
function mymodule_node_view($node, $view_mode, $langcode){
$path = current_path();
$path_alias = drupal_lookup_path('alias',$path);
$links = array( 'test' => array('title'=>'my_link', 'query'=>'', 'href'=>"{$path_alias}/nextpage") );
$node->content['my_module'] = array(
'#theme' => 'links__node__mymodule',
'#links' => $links,
'#attributes' => array('class' => array('links', 'inline')),
);
}
That creates a hyperlink called my_link across the top of my content area - which is great.
The problem starts when I click the hyperlink. Supposing I am on http://example.org/homepage and I click the hyperlink, I expect to be redirected to http://example.org/homepage/nextpage. Also, I still want to maintain the view and edit tabs of the actual node I was on. However, Drupal correctly gives me a "page not found" error.
What's interesting is if I used http://example.org/node/1 and visited http://example.org/node/1/nextpage, I don't get the issues I described above but the url is less descriptive.
To solve this problem, I am sure I have to extend hook_menu but I don't know how to account for any number of taxonomy terms leading up to the actual node title. So, I can't predict how many % I will need before the node title and then my /nextpage. However, I want /nextpage to still have the view and edit tabs of it's parent page.
This is all unexplored territory for me.
Update
I found the following function which does a great job of returning the entire node path complete with taxonomies:
$path = current_path();
$path_alias = drupal_lookup_path('alias',$path);
What I don't know is how to take advantage of this in hook_menu to dynamically create /nextpage for my nodes.
Please remember, I don't really want /nextpage to be entirely independent of the original and actual Drupal node. When on /nextpage I want to be able to have access to the view, edit etc tabs of the node.
So, /nextpage effectively is just an extension of a Drupal node page.

There is a quick way to do that. Using views module.
In the fields section choose the field you wanna view. And in the arguments add the nid.
Then add the link to the node view you already created.
The final result http://mysite/views-page/[nid]
Hope this helps... Muhammad.

I would check the node_menu() function to get some reference on how it's implemented.
Not sure on your taxonomy requirements so this might be insufficient but I'll go with what I understand.
But off the top of my head I'd go for something like:
function mymodule_menu() {
$items['node/%node/nextpage'] = array(
'title' => 'Next page',
'type' => MENU_LOCAL_TASK, // Makes it a tab on node/%node-pages
'page callback' => 'mymodule_node_page_view', // Your page display function
'page arguments' => array(1), // First will be a node object, second will be whatever value is passed in the url
// You should rip access callback and access arguments from node_menu()
);
return $items;
}
That should do something like what you are asking for.
It is also possible, easier and definitely recommended to do this with Panels/Pages (see also Chaos Tools) or arguably Views as they are quite capable of all this and generally a better way to work with Drupal's strengths than custom code.
Updated
To clarify I've simplified the menu hook and you should be able to use the below page view function. I still believe you would make a better solution using Panels and overriding node_view and such.
The MENU_LOCAL_TASK part in the menu hook should turn this into another tab along with View and Edit.
function mymodule_node_page_view($node) {
die("It works: ".$node->title);
}
Hope that's more helpful.

Related

Drupal: back-link in custom breadcrumb

On my Drupal7 have a views (results) width a exposed filter for list the nodes.
When click on a node then display a breadcrumb
ex.
Home >> results >> node-title
Thats good!
But i will make the breadcrumb 'results' a backlink.
When input ex. t then the url is:
http://www.site.com/results?title=t
I try the above url as variabele in the 'results' breadcrumb.
I hope you understand this.
Is this possible with a php snippet in custom breadcrumbs?
Yes this is possible :)
The tricky part here is having your code "remember" what the query was from the list of nodes. One option would be to add a $_GET parameter to all of the node links.
For clarity:
If you are on
http://www.site.com/results?title=t
A link to a given node on that list of results would be:
http://www.site.com/node/56?title=t
This can be done in views by modifying the output of the link. Shouldn't be too hard.
Then, to modify the breadcrumbs you need to add a function like this to template.php
function THEME_NAME_breadcrumb($variables) {
$breadcrumb = $variables['breadcrumb'];
// check to ensure this is the one you want to alter
// Custom rebuild process of breadcrumb with custom links.
if ($breadcrumb[1] == 'your_breadcrumb_id') {
// Keeping the trail/current page as non linked
$links[1] = l(t('results'), 'results', array('query' => array('title' => $_GET['title'])));
drupal_set_breadcrumb($links);
}
}
(Check my code for syntax, its untested)
Good luck!

retrieve query outside the wordpress loop with ajax.load in #content

I am working on an advanced search on wordpress based on custom taxonomies.
I'm stuck since 48h so I was hoping to have some help or thought...
Step 1 --- in the js file the query strings are created like that:
if (jQuery('#s').val() == ''){
URL = "/?genre=" + genre + '...other Stuff' #content';
}else{
URL = "/?s="+searchQueryString+"&genre=" + genre +'...other stuff' #content';
}
It nicelly load my custom loop in my #content div without changing the browser url or reloading the header, which is pretty good...so far. :-)
Step 2 --- then I wrote 2 functions in my function.php , one to load the loop with the GET[] elements on main page, using new WP_Query
and one that does the same thing for search queries:
add_action('pre_get_posts','SearchFilter');
Which is compiling my GET[] filters with the GET[s] in the content.php,
Still all good....
Step 3 --- (problem^^)---
I want to add a css class to desactivate the radio buttons located in my header.php, depending on the results in the loop.
Try-1 I thought I could create a php array to compile the terms found while the loop is happening, and then compare it with my buttons value.like that:
$args = array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'slugs');
$results = wp_get_post_terms(get_the_ID(),'category',$args);
foreach ($results as $result){
array_push($stack, $result);
}
But there is no way to retrieve the data from that array in the header afterwhile, or to create it from the header using things like global $post;since my url doesn't change.
it just shows the homepage query.
Try-2 I also thought I could encode it to json and then put some action in my js file. but so far it just return json unexpected character, and I got the feeling that even if I crack it, its not going to be the right way since its going to make the js file heavier.
May be I'm just missing something about the Global wp_query and I don't need to charge my script?
Excuse my english and the long question,
thanks a lot in advance if you have an idea,
DACO
I'm going to use wp_localize_script to export the array to my js script,
Thanks sorted

opencart - How to manually display a module inside a template file?

Let's say I want to display the specials module on the homepage in a position different than $content_top, $content_bottom, $column_left or $column_right. How do I do that? If you have some experience with this, could you give me some pointers?
The module will be display in home.tpl but I'm assuming I would need to edit the controller file home.php
To do this, you will need to make edits to two files
Firstly, you will need to edit the controller. In this example, I'm going to add the specials to the home page
So open the controller file catalog/controller/common/home.php. Somewhere before this line $this->response->setOutput($this->render()); add the following
$this->data['special_block'] = $module = $this->getChild('module/special', array(
'limit' => 5,
'image_width' => 80,
'image_height' => 80
));
The array is the settings for the module. Note that the layout, position, status and sort order aren't included, as they're irrelevant here. I've also used special_block as a unique key for the content, to avoid it conflicting with any other items that may need rendering
Then in your template file, you just need to use <?php echo $special_block; ?> wherever you want the module to go

stubs, dynamic homepage in cakePHP

I'm working on a site for a client that wants to be able to update modifying their content. The brief was to allow them to edit pages, but not create or delete them. For the site I decided to work with cakePHP, as I've heard good things.
First up, a quick explanation of my setup. I've got a single table, called 'contents', in which i'm storing each page's content. The table has a pid, a varchar 'title', a varchar 'slug' and a longtext 'body'. They're all pretty self explanitory, Each page will have it's own row, and body will be a simple HTML dump.
I've got two situations that I am having trouble with. Firstly, is setting the homepage. Cake's default is the page based on home.ctp, but that is static. Currently the page I was as the homepage is at localhost/alc/contents/view/2. I understand this is something to do with the routing, but most examples out there give half the solution, when I need every detail :P
The second problems is the slugs of the pages. Each page is currently under /contents/view/id, and i'd like this to be the slug in the database instead. Each time i try to change this (i.e. modify the view link in my index), I get an error rather than the page's content.
Any help on this would be appreciated, as there are the two things I cannot seem to grasp properly. Thanks!
By the way, you can view the site at http://www.roberttilt.name/web-dev/ALC_proto/
For the first question you need to open the /app/config/routes.php and change the line which is for the home page. i.e.:
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
need to become
Router::connect('/*', array('controller' => 'contents', 'action' => 'view'));
In your controller file /app/controllers/contents_controller.php go to action view and change it to accept empty id i.e.
function view($id = null){
if($id == null){ //Load the default home page
$this->find('first', array('conditions'=>array('default'=>1)));
} else {
//load the
$this->find('first', array('conditions'=>array('OR'=>array('slug'=>$id, 'id'=>$id))));
}
.....
}
This way if the id or slug are not provided you are loading the home page. If one of them is loaded, just use it to load the contents of the desired web page.
Your links will look like:
$this->Html->link('About', array('controller'=>'contents', 'action'=>'view', $slug_var));
The link will be converted to
About
Probably you have to take a look on the Cookbook.

What is the trick to have 2 separate user registration formin Drupal using different templates?

I have a default user registration form that cannot change. However my boss wants a second registration form that is laid out differently than the first. I am new to Drupal so some explanation would be great.
Thank you in advance
If you create a custom module you can define a path for the second menu item using hook_menu().
function user_menu() {
$items['user/custom_register'] = array(
'title' => 'Create new account',
'page callback' => 'drupal_get_form',
'page arguments' => array('user_register'),
'access callback' => 'user_register_access',
'type' => MENU_LOCAL_TASK,
'file' => 'user.pages.inc',
);
return $items;
}
Of course this will not look any different to your exsisting form, it will just be a different path.
To customize the form you have a coulpe of options, you could use hook_form_alter() and check the path. Or you could change the page arguments argument above to something which called user_register and customizes the output.
Let me save you some time, as I just solved this on a few sites. Check out the login forms here:
http://www.dogfish.com/user
http://www.inclind.com/user
This is the basic user login form. I am overriding it by telling Drupal to use a custom tpl file to load this page, and in the TPL, I am added additional elements and adding to style.css.
There is a write up on how to do that here:
http://www.lullabot.com/articles/hacking-phptemplate
Halfway down it shows you how to work with template.php to define new tpl pages for specific paths.
What you want to do is tell it when 'user' or 'user/register' is loaded, use a tpl file (you can name it). Then, you can work with the preprocessor functions and add to the page, like change the into words at the top, or remove certain form elements. The benefit is you can add all you want to the user registration form through the core Profile module or other modules, and they will still be presented here.
It will save you a lot of time this way instead of try to reinvent the user login process with your own module (I've tried that too).

Categories