I love Drupal,... to a point. And I'm going to keep slogging away at it until I get it. But for 2 months I've been stuck on a problem that seems to me to be dumb.

I keep seeing reference to "custom content types" but Drupal appears to have no such function. Maybe it's a language thing, but at best Drupal really only has one kind of content type and all other content types are merely a modification of the main "article" content type.

I know, you're all rolling around laughing yourself silly at what I just wrote there but that's what my experience is showing me. Why?

Because so far I cannot find a way to accomplish the simple task of over-riding the title url of a post. That's it. Something thousands of Drupal sites do yet either I can't ask the question right or this is precious information allowed to only a select few.

I get sent down Views tangents that go nowhere. I never could understand how Views could have the ability to replace the url in the title since as far as I can tell from the 3000 hours I've spent fooling around in Views, it has no effect what Drupal produces in the "river of news."

I'm not asking for technical support. I'm just venting.

Why isn't this functionality more intuitive in the core functionality? This is something thousands of sites do and thousands more need yet getting there is harder than setting up the whole site put together. I got a site 95% done and I'm stuck on this dumb issue that I think should be more native to Drupal than it is?

I've asked dozens of times everywhere I can looking for someone, anyone, who could answer this question and I get a lot of verbose, truncated answers meant more for someone with 30 years university and a P.h.D in computer sciences. I even ended up going off into a tangent with the series of a dozen "modulettes" of the base_core/base_link family. Good grief! That's like 20 modules just so I can over-ride a URL? And it doesn't work!

So that's really my question: why is something that should be so simple to accomplish so complicated in Drupal?

Why should I have to load 63 modules and create a content type with 78 fields and 13 Views just to over-ride a URL? (and still can't!)

I know this is simple, I just don't understand why I'm not getting it.


joelbox-Mondial-IT’s picture

Hi ThomS,
It can indeed be daunting.
I know you mention you are just venting, but it did get my attention. I have build many drupal commerce site, so i might be able to help out. Could you phrase the question again. You mention override the title on a post. I would interpret it as 'how to change the title on a node'. But that is propably not what you meant?

nicoz’s picture

I agree with @joelbox-TotalOnline.

I have read your entire post and I don't know what you are trying to do. In one statement, you are trying to override a node title, and in another, you are trying to override the URL. The problem is that you are not stating your issue coherently for others to help you. If you are having a tough time because you don't understand what language to use, try using screenshots. Help us, help you :)

modul’s picture

Drupal is slightly more difficult than most other CMS's because it's also slightly more versatile. Practically everything can be changed or modified - but that takes time and effort, that's all there is to it. There are many, many good books on "Drupal for beginners/intermediates/experts", and it certainly pays to go through one or more of them. Same thing for videos.

Now, with regard to your question, it is indeed not very clear what you want to change. A title and an URL are different things.

It may be possible that you want to override Drupal's default way of giving a path name to the node you're making (which is something like http://www.yoursite.com/node/3347 ). If you want to change that into http://www.yoursite.com/readthis , you can easily do this in the standard editing window, where you can define an "URL alias" for the node you're editing, close to the Submit button.

There are also more automatized ways to do something like this, such as the Pathauto module, and probably a bunch of similar functionality on taxonomy based (say: "tag based") modules.

Don't hesitate to specify your question - but do be specific.

ThomS’s picture

Thank you all very much for your replies. I agree with everything you have said. I have a few books on Drupal like Pro D7 Development, and they're great, but I've been unable to track down my solution.

I'd like to take you up on your offer and see if I can make any sense. I will use 2 explanations.

When a user creates content, any content, Drupal gives it a node (address/link). So a user creates a blog and when the blog/article/whatever gets published it has a node like mysite/content/user-story. When the teaser for that content gets published to the front page "river of news" the title of the post is the link to its node. That's what I'm trying to over-ride. This content type I'm trying to create is just to publish a teaser of content from another website - I need all links (especially the title) to link to the other website, not mine. I know Drupal creates the node, I'm not trying to change that, but instead of clicking on the title of the teaser and being taken to the node showing the same teaser, I want them to go directly to the other site (preferably in another browser tab, but I ain't getting greedy yet).

The second explanation is on the user side. When a user chooses this content type, I want them to be presented with only 3 fields: Headline, URL (link) and Teaser. They would cut&paste that info in there, and once published that would appear on the front page with the rest of teasers, but the title when clicked would bring them to the other website where the content originated.

Say you were building a site for people to talk about their pets. Along with being able to produce and publish their own content on the site, they also have the ability to publish (post) a teaser of content they find on other websites they would like to share.

To me, it's pretty simple. I just want the information in the URL (link) field to replace the link (URL) in the title of the post on the front page, and I thought that would be fairly straight forward. I've seen plenty of other Drupal sites do this, but they won't respond to my inquiries on how they did it.

Anyways, I hope that make sense and thanks again to all for your replies.

modul’s picture

So, your user creates http://yoursite.com/123, and when the node is published on your front page, you want clicking on that node to lead the "clicker" to http://someothersite.com/456 ? Is that it? And the link to someothersite comes from a field filled in by the original publisher?

Shouldn't be too difficult, and there are undoubtedly many ways. From the top of my head (but probably not the most "politically correct" way to do this), you could dig into your theme's node.tpl.php. There you have all kinds of variables with which you can play around (if they're not listed there, they're also in your book on Pro Drupal 7 (a splendid book, by the way - and on drupal.org). You could then change the link to "itself", which Drupal puts there by default, and change that with the contents of the field which contains the Real target link.

When I said "not politically correct", that means that people frown upon putting too much php code in the theme files, and they are correct: it's not wise to do so (because updating your theme later on may become a bit of a hassle). But just to get your feet wet, you could give it a try this way. Shouldn't be too difficult - if at least you find node.tpl.php understandable - which it is. If that method works, you can try developing your own module and do it the proper way, with some "hook" which you call in your module. It's a little bit more complicated than taking the "easy" way (node.tpl.php), but it also works.

You'll probably/definitely need the Devel module, to show you all sorts of available variables with which you can work.

Possibly, you could also make it so that the contents of the "reference field" is displayed (and clickable) on the front page, and you could disable the link of your own Drupal title. Just a hunch.

And then there are probably a bunch of "redirect" modules, which would/could/should read the contents of the field your user fills in and guide the "clicker" nicely to the goal he should reach.

ThomS’s picture

how do you put a screenshot up here?

in the meantime... is there a module that opens this up to being configured? (please click on the link to see the screenshot)


i'm pretty sure this is where Drupal is setting up the parameters i'd like to change.

WorldFallz’s picture

Yes, the pathauto module allows urls to be aliased via patterns, but they'll be local to the site. afaik, you can't set it up to alias to a different site.

and you can use the auto_nodetitle module to format nodetitles in a similar manner.

Care about the future of the Drupal.org forums? Please join our conversation and show support for improving the forums infrastructure.

modul’s picture

This link, http://coolestguyplanettech.com/downtown/drupal-seo-settings-configuring... , appears to be able to put you on the right track. I think your solution lies in the Token module. It appears that the D7 Token module (https://drupal.org/documentation/modules/token) Does understand the contents of fields (follow the link at the bottom, "Field tokens", to https://drupal.org/node/1299662). If I understand this correctly, you could make use of the tokenized contents of your user-defined-URL, and use it to fill the href of your node title. Don't ask me if and how and where (you'd have to study the Token documentation), but according to this information, it should be possible.

modul’s picture

Another approach, instead of meddling with Token and (probably) having to write your own module: why don't you make another frontpage alltogether? You could make a View of your "user defined URLs" with whatever text you want added, and use that View as your new front page. Or am I missing an important point here,

ThomS’s picture

I think your first post above looks very promising. Sound very much like what I want to do. Thank you very much for the links.

As far as your second suggestion, it isn't that your missing anything, it's just that that wouldn't be a good fit for what I need. I need Drupal's river of news since my user base are not so internet savvy and get impatient when there's too much clicking around. All content needs to be on the front page in teaser form.

I'm away for the weekend so I won't be able to see if your info is a fit for me but I'm optimistic by the sound of it that I might get closer to solving my problem. I'll let you know soon.


ThomS’s picture

I can't believe how excruciatingly difficult it is to find a solution to this issue. This should be easier.

nicoz’s picture

Your issue is not a difficult one. I am not sure why the others in this thread are talking about creating your own
Module, editing template files and using devel. IMHO, they are overcomplicating your issue and only creating more confusion.

You are going to create a content type with three fields (title, body and URL). Then create a page view (using the views module) that lists those fields. Change the title field to link to the URL in the URL field rather than link to the node. Then go to site settings and change the default front page to your view page.

ThomS’s picture

I would tend to like to agree with you nicoz, but I'm not sure.

The solution you pointed out could probably work but my site has multiple content types that share the front page and creating a View like the one you described would give me a front page with only teasers of this content type. i apologize if I missed something, but Views works on a level below where this change needs to occur. In other words, Views only modifies the output of what is already in the node, so if the node is published to the front page, it will always have the internal link to the created node. If I needed only to display a front page of teasers for this one content type, then I agree with your method. But as soon as I want this content type to share the front page river of news I hit a wall.

The more I try to learn to overcome this problem the more I'm confusing myself. I'm even having a hard time getting the language straight in my head. So I realize that many people trying to help me are also having a hard time understanding me, because I'm starting to have a hard time understanding myself.

What's really hard is determining which level to attack this problem on: the entity level, node level, content level or field level? I need to change what Drupal is outputting as the link on the teaser title of this content type. That's all.

This is the frustrating thing for me. I only need to do that (essentially) but when I try to investigate things like Token and Views and Entity API etc, these things get into some pretty spacy stuff (which is great) but way beyond the scope of what I want, and I cannot find anything directly relatable I can use to at least point me in the right direction. I've read 1000+ pages so far just on this and I still come up empty handed. the answer is either buried inside some convoluted principle I don't yet understand, or too simple for me to see.

Thanks for the help, I do appreciate it.

nicoz’s picture

Since the URL field is the unique field to this content type, then use the "no results behaviour" in views to show the fields of the other content types as needed.

Essentially setup the view with your fields that emulate the frontpage as you need it but then set them to "Exclude from display". Add the URL field and use the replacement patterns to markup the "Rewrite the output of this field" to display as the URL content type. Then setup the "no results behaviour" on the same field to use the "replacement patterns" ("tokens") of the other content types. Don't forget to check off "Hide rewriting if empty".

ThomS’s picture

I've noticed that Views comes bundled with a view called Front page. Do you think that view might be helpful here?

nicoz’s picture

Yes. If you are not familiar with views yet, clone the one they provide and customize to your needs.

John Pitcairn’s picture

So all you want is that the title link in the teaser for a specific content type should be replaced by the url from a link field in that content type. You'd want to do that wherever that teaser appears, which may not necessarily be homepage-only as your site grows. Let's try to do this in the simplest way possible, without adding more modules or views.

That link is generally applied to the node title at the theme level, so at the simplest, you need to override either a theme template function, or a theme node.tpl template file. What theme are you using?

Do you consider this to be business logic, ie you don't want your override to go away if somebody switches the theme?

ThomS’s picture

I've sub-themed Pixture_Reloaded.

EDIT: I realize that trying to help me with Pix_Reload may be difficult to sort out, so if it is easier I can use any theme you like. If I can get an idea how to make it work in one theme then I can wrestle with it in Pix. I just mention this because in looking around I was reminded that Adaptive Themes et al tend to structure their themes in a more convoluted way, so maybe using a simpler theme just to figure this out would be less complicated. Thom

modul’s picture

I'm not at all familiar with AdaptiveTheme and Pixture Reload. But since they are "just" themes, I'd imagine that the basics of other themes still apply.

I notice that in the Templates folder of Pixture Reload, there is no "node.tpl.php", but only page.tpl.php and comment.tpl.php. It would make sense to try to find out if AdaptiveTheme/Pixture understand the presence of node.tpl.php. If so, you could take the standard theme of Drupal 7 (Bartik) and meddle with what you find there. You could copy Bartik's node.tpl.php to the template folder of Pixture. Add some echo code here or there, just to see if it gets called at all. If so, we can do business. If not, the rest of this message is of no use.

Supposing node.tpl.php gets called, look at (roughly) line 85 or something of your "Bartik" node.tpl.php. That's where the node's title is formed.

As you will see, it's a line like this:

 <h2<?php print $title_attributes; ?>>
      <a href="<?php print $node_url; ?>"><?php print $title; ?></a>

Now, let's take a look at your user-supplied url field. I don't know its name. Let's say it's "user_supplied_url". In node.tpl.php (still supposing that file is called...), you could change the variable $node_url in the code above with something like this:

$user_url = $node->field_user_supplied_url['und'][0]['value'];
print '<a href="' . $user_url . '">' . $title . '</a>';

If that code works, clicking will not lead to the node, but to the url supplied by the user. I suppose that is what you wanted.

The ['und'] may be ['en'], ['fr'] or whatever, if your site has different languages. If it does not, the ['und'] will be applicable as written above. Using the priceless Devel module will tell you A Lot about what variables you can play with.

Further meddling can be done with for instance the drupal_is_front_page() function, to only do this substitution on your front page. You also have the $teaser variable in node.tpl.php to only do the substitution in teaser lists etc. You also know the node-type variable, so that you can only make the substitution only take place in the content type which has the user-supplied url.

I'll get scolded because of doing more php stuff in the template than I'm supposed to. So sue me :-).

Anyway, all this is entirely useless if you cannot use node.tpl.php in your theme. So, find that out first. If so, you're on your way. Good luck!

John Pitcairn’s picture

@modul: Use field_get_items() to extract field values, to allow translation/language support. Also check there is a value in the field:

if ($variables['teaser'] && ($user_url = field_get_items('node', $node, 'field_user_supplied_url'))) {
  print '<a href="' . $user_url[0]['value'] . '">' . $title . '</a>';

That said, if it's desirable that this change is unaffected by future theme changes (business logic vs presentation logic), I would probably make a small module to implement template_preprocess_node() and override $variables['node_url'] there.

ThomS’s picture

Your turning into a superhero to me modul! I'm in the process of trying this stuff out.

Thank you very much! I'll keep you updated.

ThomS’s picture

I'm feeling good about this piece of code. Thank you John!

ThomS’s picture

What I seem to be finding out here is that a module is probably going to be my only hope.

Pix_Reloaded seems to be a very disguised theme that does everything through .inc files. I cannot find any of those strings in any of the files in Pix. Seems that Pix is coded in such a way that you would have to pay to find out how to modify it.

In my subtheme of Pix there is a a file called template.php that seems to be the place I'm expected to put in code to override stuff like this but unless I really know what to put there it looks like it would change everything globally for all nodes. Whew! Drupal is Com Pli Cated! Throw Pixture_reloaded into the mix and your brain will explode.

I have a much better understanding however of what direction I need to go as well as more knowledge so at least I'm moving forward in those respects. I think John is right in that a module will have to be the route taken, all things considered. If this change were to disappear every time there was an upgrade I'd lose all my hair.

I'm going to keep fishing around inside the theme in the meantime to see if I can still crack this egg at that level. I'd love to figure out how Pix is doing this without any of the normal files or code found in other themes. Eventually I will have to replace Pix as my theme when I become proficient enough to create my own because Pix is coded and structured to vector users of the theme to a cash-output situation and for a free community-based website I don't have the budget for thousands in consulting fees.

Again, thank you all very much for the help.

nigelw’s picture

Seems that Pix is coded in such a way that you would have to pay to find out how to modify it.

The theme is built just like any other theme and it's built upon AT which is a theme framework which is pretty flexible. There is nothing unique or proprietary about it that would require you to "pay" to find out how to modify it. There is tons of documentation to support it. See http://adaptivethemes.com/documentation

If this change were to disappear every time there was an upgrade I'd lose all my hair.

This is why you create a subtheme rather than hacking apart a contributed theme. Also, if you use nicoz's approach above and use views then, there is no coding required and it is theme agnostic.

Good luck.

John Pitcairn’s picture

For a module-based approach, implementing hook_preprocess_node() should work. Something like:

 * Implements hook_preprocess_node().
function mymodule_preprocess_node(&$variables) {
  if ($variables['teaser'] && ($url = field_get_items('node', $variables['node'], 'field_user_supplied_url'))) {
    $variables['node_url'] = check_url($url[0]['value']);

I'd recommend using a link field for the user-supplied url field, to get built-in validation etc. In which case the value will be $url[0]['url']

ThomS’s picture

Thank you very, very much John. That REALLY helps me a lot!

ThomS’s picture

Well, I am still a little confused but at least I'm making progress. I've been playing around with John's code in a module with no success but I'm learning. Thanks to everyone, and @modul and @John Pitcairn, I have a much better understanding of how Drupal works and where I should be looking.

The code John posted above is producing a result though. Finally, after months of banging my head the link is finally changing! But instead of using the url from the user provided link field its outputting a link to the homepage. I haven't a clue why yet, but I'm sure it's because I'm still missing something. I'm also a bit suspicious of the content type I created; it was made before I got this new code and is probably foobar with all the mucking around I've done in it.

I'm going to revert back to a brand new install of D7 (Bartik) with only the link module loaded. I will create a content type with a machine name of newz that will have a title field, a link field and a body for a teaser. My link field will have a machine name of weblink.

I'm still very new to all this and I'm spending a lot of time in my Pro D7 Devel book trying to learn all this. If anybody has anymore suggestions or can point out where I've gone astray I'll be very happy to hear from you.


modul’s picture

ThomS, it would be nice if you could add the module (.module and .info files) as an attachment. Maybe we can help you figure things out on the basis of actual code. No promises, though :-)

ThomS’s picture

I'm sorry I don't seem to understand how to add an attachment here, but here's the code:


name = URL Replace
description = Replaces the title url in a teaser post
core = 7.x
package = Fields

Files[] = url_replace.module


* Implements hook_preprocess_node().
function url_replace_preprocess_node(&$variables) {
  if ($variables['teaser'] && ($url = field_get_items('node', $variables['node'], 'field_weblink'))) {
    $variables['node_url'] = check_url($url[0]['value']);


ThomS’s picture

one of my problems seems to be in the last line where it says "value."

John Pitcairn’s picture

Yes, that's not the correct array key if you are using a link field as I noted earlier. It needs to be $url[0]['url'].

ThomS’s picture

Thank you John, and I'm sorry I made you have to tell me that twice ;-)

And with that last little correction IT WORKS! I can't believe it, after all this time, but I got goose-pimply when I rolled my mouse over the title and there was that inputted link.

Thank you all very much, and thank you John and modul especially. You guys helped me learn a lot and now finally I can move forward and finish this site and get it live.

I feel good that we accomplished this with a module so there will be no worries of it getting changed and screwing up things for me in the future!

Again, you have my everlasting gratitude.

modul’s picture

Glad you have it working, ThomS. Actually, this story is a nice proof of what Drupal is: not so easy to grasp, but goddamn Strong. After all, it takes just a handful of lines of code to do what you intended to do. It also shows the importance of the Drupal community. Good luck with your site, and when it's operational, let's hear about it.

John Pitcairn’s picture

One last suggestion - ensure the replacement only runs on the correct node type:

* Implements hook_preprocess_node().
function url_replace_preprocess_node(&$variables) {
  if ($variables['node']->type != 'my_node_type') {


ThomS’s picture

Again John, a zillion thanks! You've really helped me learn a lot.

@modul: Thank you as well for your help. When the site goes live I will be more than happy to share it with you guys.

When I started this post I was "frustrated and confused" because I felt deep down inside that this would be simple, but I just couldn't get any help. Well, the reason I was having such a hard time getting help was I really didn't know how to ask for what I wanted.

This thread and the help I received here has renewed my love of Drupal and the Drupal community that attracted me to Drupal in the first place. The time and effort taken by the posters here to help me through this issue really demonstrated that to me. I wrote that post as a sort of rant I guess, not really expecting any answer beyond being told to wipe my nose.

The first posters showed up to calm me down and help me re-ask my question in a way that made more sense. And then the answers started coming. Right at that early stage, I was taught that I had been looking in the wrong place and approaching the problem the wrong way. Just that alone at that point was enough to make me happy. I still didn't know how to do it, but I at least knew where to start.

But it didn't stop there and the replies kept coming until there was a solution and that blows my mind.

Thanks to the help I've gotten here I am much farther ahead than I would be alone.

I look forward to the day that I too can help others here the way you've helped me.

Thank you very much!