Drupal 7- How to make a custom module for only front page? - drupal

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.

Related

Drupal page content

I'm new to drupal and reading through docs, but hoping to get an explanation for something.
I have a page called page--type-home-page.tpl.php.
Part of this page prints render($page['content'])). I want to remove something that is rendered as part of the page content from the page, but don't understand where this comes from and where/how to look.
Thanks!
Assuming you're talking about Drupal-7
Well the $page['content'] contains a string, which is a rendered version of what's injected into the content region of your theme.
By default, the only block in this region is the "Main page content" block that is generated by the Drupal core. Many things can generate this content but it always pass through the menu API. For instance, if you're viewing a node, the URL used is: node/12. The node module declares a menu entry for node/%node, this menu entry contains a callback function that will render whatever the module wants to render. The module, then, may use different strategy to render it's content from a simple function to a complex imbrication of templates.
The key to alter what's in the box, sorry, what's in the $page['content'], is to know what is rendered and to understand how it's rendered.
If it's a node, first you want to look if you can achieve your goal through the display settings of the content type. admin/structure/types/manage/page/display: And this is true for all entities (users, comments, taxonomy term etc.) Because this is the first thing the module of these entities will put together when they'll try to render your content.
If this is not enough to achieve your goal, you can look into the module that renders the path to see if it hasn't a .tpl.php. You'll be able to re-use it in your theme. You'll want to copy/paste the file in your theme and edit it.
If the module do not have a tpl file to override, try a template suggestion: here's a list from Drupal.org
Ex: node--type.tpl.php
If all this doesn't satisfy your need, you'll have to dig into preprocess functions; Those functions allow you to modify what's in the variables passed to .tpl.php files. That's a little more advanced and I recommend you to read this previous stackoverflow question/answer
Simply, don't use that $page['content'] which prints all content, but place your custom template code instead and print separate field values where you need them like:
<?php print render($content['your_field_name']); ?>
https://drupal.stackexchange.com/questions/30063/how-to-print-fields-in-node-tpl-php
If you want to do just simple styling, like excluding some field you can use content type display options like mgadrat explained, but if you want to use some complex styling, with totally custom html this solution is easier.

Prepopulate Content Type Args when going to /admin/content in Drupal 7

I created a Drupal site. The admins who will be using the site for content management have no Drupal knowledge and I have been tasked with making this as easy as possible for them. I'm creating an admin control panel and I want a quick link that takes them to the admin content page, but with the "content type" prefilled. For example, for content I have pages, events, resources, and testimonials. I want to provide them with a quick link for editing content type EVENTS only. So it would go directly to admin/content with the type filter set to "events". The URL does not currently add args or anything like that.
Anyone know of a way to do this?
yes you can do this- just use this module: Drupal admin views which supports a REGULAR VIEW for admin/content. The View is set to use ajax though- just remove this option and save it and call /admin/content then. There you will see the resulting filters in the URL (you can even set their keys to a value you like inside the view). Set back to use ajax (if you like) and use the keys in the URL for type it's simple just call /admin/content?type=YOURTYPE

Wordpress, alternative single post template

For a project of mine I need to define an alternative template for single posts.
To be more specific I need each post to be displayed as usual when the website is browsed but I need to create different single pages reachable from different URL to create a sort of a mini-website for each post.
(I'm actually using the WooCommerce plugin and what I need to do is to create a mini-website for each product. This needs to be something "outside" from the main website, with a complete different graphic template and is going to be reachable through a QR-code).
Hope it makes a bit of sense.
Thanks for your advices and/or suggestions.
Angelo
I think the easiest way to do that is by registering a custom post type for the special posts that get this special "single.php" template. Then, you can simply write a new single template titled post-[custom post_type].php. Any post you register of this type will use that template.
OR...
If you don't actually need them to be posts, it's even easier if you publish them as pages. By default, pages let you assign a specific page template in the edit screen. So you could make any number of custom templates. Just make sure you add the special header:
/* Template Name: Custom Page */
...so WP knows it's a page template.

Drupal arguments in a menu

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.

How to embed a node on homepage in Drupal 6?

How can I embed a node on the front page in Drupal 6. The node basically has the image upload field along with title and description. I want it to some how appear on the homepage alongwith a "views" which shows the uploaded images at the bottom.
What I want is to give the users an ability to create content which is right now available at .../node/photo/add. I want to somehow show this box which lets one create content i.e. upload photo with title and description on the homepage.
It's basically just an attempt at creating something like imageshack as an experiment.
I am pretty n00b when it comes to drupal so please be more descriptive.
Jukebox's solution works as a point-and-click method. If you want to do it with code, it's more like this:
create a glue module Handbook | Example Blog Post
turn it on in admin/build/modules
create a menu item using hook_menu() that will become the page
embed the node with node_view()
embed the view (blog post)
in admin/settings/site-information set your page to the
You can use the Node Blocks module to, well, turn your node into a block. This means that you can go to the /admin/build/block page and place your node in a particular region.
After installing the module, edit the Content Type of the node you want to turn into a block. Under Workflow Settings, Available As Block, choose Enable.
Now you can go to /admin/build/block and you can see some new blocks. Just choose the one you want and place it in the region of your choice. You can also configure that block's visibility settings from there as well.
If your planning on having a more complicated home page at any point in the future I'd highly recommend using Panels to do this. It will allow you to arrange your front page with views and nodes in a grid method.

Resources