官术网_书友最值得收藏!

Teaser Thumbnails

Our next project requires us to use teaser thumbnails for articles. We have been hired by The Seedy Grapevine, a local social gossip column, to create an online version of its weekly rag. One of its requirements is to add an optional teaser image to its articles, which will display as a thumbnail on the front page and a larger image on the article page.

As is usually the case, there are many possible solutions to this need. But because it's not paying us much, and we want to just get the job done quickly, we're going to do the easiest thing we can. Yet its editors will be happy because the quick route is also easy for them to use. It's out of the box, and though there are certainly more complex solutions (often required for complex needs), our solution will harness the power of the Image module that we've already seen.

Image attach

The Image attach module is included in the Image download. Since we've already installed and configured that module, we just need to visit Administer | Site building | Modules (at /admin/build/modules) and activate the Image attach module.

This will allow us to attach image nodes to any other type of content. For the purpose of this project, we will use the Story type content, which is built-in and active by default on all Drupal sites. For a more complex solution, we would probably build our own type with multiple image fields (which we'll do in the next chapter). But we would still be able to use this module with those types, if it were the best solution.

Image attach Content Settings

To attach images to a content type, we must visit the settings page for that type. In this case, we'll go to Administer | Content management | Content types | Story (at /admin/content/node-type/story):

Image attach Content Settings

Now we just change the settings we need. Obviously, we'll first enable Attach Images. Leaving the Teaser image size at Thumbnail, we'll change the Full node image size to Preview.

The weights (from lowest to highest) determine where in the content the image will be displayed in relation to the body and fields (if using CCK fields) of the node type.

Attaching Images to Content

Now we are ready for our editors to actually begin attaching the images. As with images, you may wish users with an editor role to be able to create stories on the site by assigning that permission at Administer | User management | Permissions (at /admin/user/permissions). Users in this example must have both the permission to create story content and to create image content.

Putting on our editor hat, we go to Create content | Create Story (at /node/add/story). We'll add a juicy title, the body content of our article, and then open the fieldset that reads Attached images:

Attaching Images to Content

We can go ahead and insert an existing image that's been uploaded to the site from the Existing Image drop-down selector, or we can upload a new image directly from this form. In our example, we'll upload our new image here, hit Save, and see the new image magically float into our content!

Attaching Images to Content

Navigating back to our home page, we'll see the new image as a teaser thumbnail for our new story as well:

Attaching Images to Content

Note that you may not want editors to be able to attach existing images to content. For instance, if you have a site with multiple uses of image nodes, such as with a gallery, it may get too confusing to keep them sorted. On the other hand, note also that image nodes created with Image attach will automatically be marked as not published and so they will not show up for users except as an attached image.

To disable the option to attach existing images, navigate to Administer | Site configuration | Images | Image attach (at/admin/settings/image/image_attach).

You may wish to change the placement of the attached image. For the most part, you'll need to change your theme's stylesheet to do this. The Image attach module automatically floats attached images to the right using its image_attach.css file. We'll learn more about overriding stylesheets in later chapters.

主站蜘蛛池模板: 昌黎县| 浮山县| 宜黄县| 咸宁市| 华蓥市| 广东省| 图木舒克市| 义乌市| 乌苏市| 酒泉市| 凯里市| 北票市| 恭城| 八宿县| 夏邑县| 天镇县| 鄂州市| 新平| 兴业县| 太原市| 九寨沟县| 雷山县| 牙克石市| 宁远县| 泽库县| 南汇区| 张掖市| 靖江市| 双牌县| 汝城县| 喀喇| 四子王旗| 休宁县| 温宿县| 拉萨市| 克拉玛依市| 岑巩县| 兴安县| 古丈县| 上饶县| 东港市|