I'm trying to create custom URLs for my menu items, such as mysite.com/aboutus rather than /node/2 or however it has it by default. In the menu configuration I changed the paths to what I want them to be, but I don't know how to change the paths of the pages to a custom name, rather than what Drupal defaults it as.
Turn on the Path module, and download Pathauto. You can then create aliasing rules per content type, users, and taxonomy, and you can forget having to do this ever again.
Related
So say I create some custom fields which can be edited via the front page editor.
I save these changes and want users of my theme to be able to see all of the custom fields I have made as soon as the theme is installed
This way, i can create a theme with pre-defined custom fields all over the website so users who install the theme can edit the custom fields straight away.
Otherwise, all the work done via advanced custom fields is rather pointless as when the theme is packaged, the user won't have access to the database that stores the files. I hope what I am asking makes sense!
EDIT: If this is not possible at all then I would accept that as an answer. If it is not possible then I would need to export then import the database for the made custom fields to display on a client's machine after they install the theme correct?
Totally reasonable question, and something that ACF has thought about and created a guide for. There are basically two parts to this guide, which I'll summarize below:
The actual ACF plugin must be included with your theme, which you can do by either:
Bundling the actual ACF PHP code with your theme (the actual plugin files)
Or, provide a link to the ACF plugin page and prompt users to install the plugin as part of your theme readme.
Including the specific custom fields that go with your theme - this is what your question is mostly asking about. Again, a few different ways to do this:
As a new feature of ACF, you can register custom fields with your theme by using JSON files instead of storing the configuration in the SQL database. This is what I personally use, since it is crazy easy to configure (just create an acf-json folder in the root of your theme) and allows you to use version-control (like GIT) to track custom field changes.
If you prefer the old way, you can register your custom fields in your theme's functions.php file.
Some additional information I can provide:
What about the storage of ACF values, not the configuration?
There is only one "database" for a given Wordpress installation, and the way ACF stores values that users have entered for custom fields with a given post is in the "wp_postmeta" table, by association the value with the post ID, field label (changeable), and field ID (permanent).
This is actually beneficial to you as a theme developer, because it means that if a user does something like installs your theme, enters a bunch of custom field values, accidentally uninstalls your theme or switches to a different one, and then wants to re-enable it, no data is lost.
Ensuring ACF gets installed with your theme
If you choose not to bundle the ACF source with your theme, and instead prompt users to manually install the plugin through the plugin directory, you might want to put some checks into your theme to ensure they do so. You can use something like if(!function_exists('the_field')){ /* Block use of your theme until installed */ } in some strategic spots in your theme code to check if ACF is installed, and if it is not, handle that appropriately and prompt admin to install.
My drupal site generates long links like:
example.com/drupal/blog/what-we-do/solutions/about-us/
This link works and shows the blog page:
example.com/drupal/blog/
how can i get rid off these kind of links?
Disable the path module in your Drupal installation.
If you want to keep using the path module and delete only some of your aliases visit the page admin/config/search/path and delete whatever you want.
When you create new content you can uncheck the automatic alias generation and blank the text field where you write the alias.
You will still be able to access the content by using node/[NODE_ID]
If you want to do that automatically depending on the type of content, I think you can use pathauto
The Pathauto module automatically generates URL/path aliases for various kinds of content (nodes, taxonomy terms, users) without requiring the user to manually specify the path alias.
so..I created page--front.tpl.php in my theme directory and it works fine.
now, how do I make a variable that can be used in the page--front.tpl.php?
I can write my php codes inside page--front.tpl.php, but I think there is a better way.
added:
on the front page, I am going to query video and news nodes ONLY. That is why I want to make a new module for only front page.
any suggestions?
I'm not sure what you are trying to achieve here, but OK. You have two options: one is what you're doing now. Write your custom PHP in page--front.tpl.php and you'll be fine. The other is ditching the file and working only with page.tpl.php.
The variable $is_front tells you whether you're on the front page. You can write custom PHP in a conditional block: if ($is_front) { ... }.
Also, you can create a custom block (a view, perhaps, depending on your needs) and set its display restrictions to "only on the listed pages" - and list there. You'll have a custom view loaded only on the front page.
All you need to do have a custom front page is configure your front page in the site information settins (admin/settings/site-information in D6).
Creating a module to display that content is then a completely different thing.
What I would really suggest is looking at Views if you don't know it already. That allows you to build lists of things (nodes, users, ...) and expose them as pages, blocks, rss feeds and much more. You can create a list of nodes with types video and news, expose that as a page and then just point your front page to the path of your view.
you might try using the views module to create your list of videos and nodes. You can set a views page to be your homepage in the site settings.
By default on a page I have the following menu:
Profile /profile
Albums /album
Awards /awards
Going to any of those pages will load the page default.
If I go to a page on my site such as /mycontent/1 I wish to change a the menu to be the following.
Profile /profile/1
Albums /album/1
Awards /awards/1
I want to pass the argument (nid) to the menu. Is this possible?
Update
The selected answer does do what I asked. I however have changed how I am doing things to use Panels to display the content. I am then using some CSS and JavaScript to hide and show content. With views caching it seems to be working well.
Yes,use arg(0),arg(1), or arg(2) depending on which variable you want to use. It will use the path like the indexes of an array (0/1/2/3/4/etc...). Drupal will send you these variables as they were before the path was aliased if that is something that has been applied to it. Why are you passing the variable? There is probably a better way to do it the "Drupal" way..
Actually I am working on this same problem currently where I need to translate an aliased path: dept/profile/1 to load node/1223/profile/1 where 1 is the ID of the profile to show.
What I am using now is the URL Alter module and implementing the hook it gives to enable this feature. If you are interested in this maybe we can see if it is possible to get module out with a GUI.
My thread on this that is active now: Using module: url_alter and it's hook: hook_url_outbound_alter()
I am using a node that houses a panel which has a view inside it, for reasons that are site specific.
Node reference fields in Drupal are displayed as lists by default. Is there a way to change that?
I'd like to output them as JSON so I can create a fancy JavaScript visualization.
You can modify it in 2 ways: via custom module with function hook_form_alter or via theming (preprocessing form or templating form).
http://api.drupal.org/api/function/hook_form_alter/6
http://www.lullabot.com/articles/modifying-forms-drupal-5-and-6
For AHAH: http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html/6#ahah
Also, nodereference already have little ahah: "autocomplete" in field editing of custom node type.
Consider the Content Templates (Contemplate) module. Here is a quote about it (from the module's project page):
... allows modification of Drupal's teaser and body fields using administrator defined templates. These templates use PHP code and all of the node object variables are available for use in the template. An example node object is displayed and it is as simple as clicking on its properties to add them to the current template.
This module was written to solve a need with the Content Construction Kit (CCK), where it had a tendency toward outputting content in a not-very-pretty way. And as such, it dovetails nicely with CCK, adding a "template" tab to CCK content-type editing pages and pre-populating the templates with CCK's default layout. This makes it easy to rearrange fields, output different fields for teaser and body, remove the field title headers, output fields wrapped for use with tabs.module (part of JSTools), or anything you need.
But Content Template can actually be used on any node type and allows modification of the teaser and body properties before they go out in an RSS feed, search index, or are handed off to the theme. Additionally, ConTemplate can choose to add any files, images, or other media to RSS feeds as an attachment.
Templates are normally stored in the database but it is also possible to create disk-based templates which live in your sites directory and can be inherited across multisite installations in the same way as themes or modules.
Try the Custom Formatters module, simply make a custom formatter to render the node out exactly how you want it, then output the formatter to code or to a Feature for deployment.