9 August 2010
Editing a WordPress theme with Dreamweaver CS5 – Part 1
Editing a WordPress theme with Dreamweaver CS5 – Part 2
Basic working knowledge of Dreamweaver, web standards (for example, XHTML and CSS), and PHP
Beginning
This is Part 3 of a four-part tutorial on editing WordPress themes using Adobe Dreamweaver CS5. Part 1 covers the basics of WordPress and the components of a WordPress theme. Part 2 covers setting up WordPress locally, installing a local server (XAMPP on Windows or MAMP on Mac OS X), creating a local Dreamweaver site and testing server, configuring code hinting, installing theme files, and previewing the main theme file using Live View in Dreamweaver. In this part, you edit the theme files in the MyTheme folder by using Dreamweaver to add a company logo to the header, change the styling of the post titles, and add a menu bar.
You'll need to complete the steps in Part 2 before completing this part of the tutorial series.
This article is divided into the following sections:
Most WordPress themes use a text title and tagline, which can be specified in the General Settings of the WordPress administration panel. If you have some experience creating images in Adobe Photoshop, Adobe Illustrator, or Adobe Fireworks, you can easily create a custom logo for your blog. In this section, I'll show you how to create a logo in Illustrator, and then insert the logo into your blog.
The logo will be placed in the header.php file, which is one of the theme files available in the MyTheme directory you set up in Part 2 of this tutorial.
Follow these step to determine the maximum height of the logo for this theme.
.bannerArea .container in the bottom of the panel.Notice that the height property shows that the div is 83px in height. This is the maximum height for the logo you are about to create.
Note: If you can't see the Properties For area of the CSS Styles panel, you may need to resize the panel and make it taller.
Using Adobe Illustrator CS5 (you can also use Adobe Photoshop or Adobe Fireworks), create a new file with a height of 83 pixels and a width appropriate for your logo (for example, 300 pixels).
Here are the steps for creating the image in Illustrator:
Now that you have a new logo, you can use it in your theme:
<p class="title"><a href="<?php echo get_option('home'); ?>/">
<?php bloginfo('name'); ?>
</a><br />
<span class="description">
<?php bloginfo('description'); ?>
</span></p>
Next, you need to link the logo to your blog home page. Many users are accustomed to clicking a site logo to return to the home page. You can use either a static link or a dynamic link that is created when the blog is live. A static link will break if, for example, the blog URL changes. A dynamic link is a convenient way to create page menus, and you can later change page slugs without breaking links, as the IDs will stay the same. However, this can increase database queries.
Follow these steps to first create a static link:
http://www.yourblogdomain.com.
This link will not change, unless you edit it in the code or in the Property inspector again. Next, you will see how to create a dynamic link.
<img src="images/blog_head.png<a href="<?php echo get_option('home');?>">
This code will retrieve the home link you specified in your blog settings and assign it to your logo once your theme is live. The get_option('home'); call invokes a built-in function in WordPress to retrieve the home page—as specified by 'home'.
border="0" to the img tag to remove the border.</a> after the img tag. The code should now look like this:
<a href="<?php echo get_option('home');?>"><img src="images/blog_head.png" width="300" height="83" alt="company blog" border="0" /></a>
The final step is to change the relative logo image link to an absolute link. As the image is currently inserted, your blog will look for the logo image in the images subfolder for the current page. WordPress permalinks can be configured many different ways; to ensure the logo will display on every page regardless of your permalink structure, the img tag needs an absolute link to the image.
src attribute of the img tag as follows (see Figure 4):<a href="<?php echo get_option('home');?>"><img src="<?php bloginfo('template_url'); ?>/images/blog_head.png" width="300" height="83" alt="company blog" border="0" /></a>
WordPress translates the bloginfo('template_url') tag into the proper directory structure for the location of your theme. Since the images directory resides within your theme folder, you will have an absolute link to your blog logo on every page of your blog.
Now you're ready to test the index page with the new logo.
Post titles should be styled to capture the attention of your readers. The post title font, color, spacing, and border for the sample theme are easily changed via the style sheet. The post titles on the home page (index.php) and the archives (archive.php) of the theme are enclosed in H2 tags with the class of pagetitle. The post titles on the individual pages (single.php and page.php) are H1 tags for SEO purposes, and the pagetitle class is also applied to the H1 tags.
The code for the index.php page in the MyTheme folder for the titles is as follows:
<h2 class="posttitle"><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></h2>
By applying the posttitle class to both the H1 and H2 tags, post title tags on any page can be quickly changed, while still leaving the normal H1 and H2 tags with their default style. Figure 6 shows the default title style for the sample theme.
To change the post title style, you need to create the posttitle class in the style.css file.
In the Tag Selector at the bottom of the Document window, you will see <h2.posttitle>. This indicates that a posttitle class is applied to the h2 (heading).
.posttitle {
font-family: Georgia;
color:#900;
font-size: 24px;
border-bottom: 1px solid #F2F2F2;
padding-bottom: 5px;
}
The title inherits the font style from the H1 and H2 tags and the link color from the <a> tag. The color property added above only changes the color of the titles on the pages, not the post titles, because page titles (there aren't any on this page) are not links. So you need to add a new class specifically targeting the post title link to give it the same red color as the unlinked page titles.
.posttitle a {
color:#900;
}
.posttitle a:hover {
color:#555;
}
After adding the above code to the style.css file, the post and page titles are now red (see Figure 7).
Every WordPress theme designer codes titles a little differently, so if you're customizing a theme other than the sample theme, you will need to identify the tags used in your theme before you can style the titles.
A menu system can add significant value to a theme. With WordPress version 3.0, there is an easy way to add a menu or multiple menu systems to your page. Follow these steps to get started:
add_action( 'init', 'register_my_menu' );
function register_my_menu() {
register_nav_menu( 'primary-menu', __( 'Primary Menu' ) );
}
This code will register the menu and tell WordPress that your theme will use the new menu system. The Primary Menu is the name of the menu, and you'll use this name to identify it in the admin area of your WordPress blog. Likewise, primary-menu is the slug that you can use to identify the menu in the code.
Note: You can also register multiple menus using register_my_menus and an array. For more information, see register nav menus in the WordPress Codex.
Next you need to add code to the header of your theme to tell WordPress where to insert the menu.
<?php wp_nav_menu( array( 'theme_location' => 'primary-menu' ) ); ?>
The final code will look like this (see Figure 9):
<div class="topnavigationgroup">
<?php wp_nav_menu( array( 'theme_location' => 'primary-menu' ) ); ?>
</div>
The next step is to customize the menu.
Note: Typically, I use "admin" for the username and password on my local WordPress installation. This is not a good idea for WordPress installations on the web.
Recall that "Primary Menu" is the name of the menu specified in the functions.php file. You can create a whole series of menus by clicking the + (plus sign) to the right of the Primary Menu tab. You then tell WordPress which menu to use for this theme by selecting it from the Theme Locations menu.
The pages you selected are now listed as gray boxes in the Primary Menu area (see Figure 11). (Your menu may have different items in it depending on the pages created in your WordPress administration panel). You can drag the pages up or down to reorder how they will appear in the menu.
Note: If you drag the pages to rearrange their order, make sure to click the Save Menu button again.
You can also add menu items that are not pages. Simply use the Custom Links section of the Menus page to add a URL and Label, which appear in the menu.
Of course, you may want to add some CSS styling to style that menu. I'll leave that part up to you. Basically you'll need to edit the style.css file in your MyTheme folder and add at least two styles; for example (see Figure 13):
li.menu-item {
list-style-type:none;
float:left;
}
li.menu-item a {
padding:4px 10px;
text-decoration:none;
display:block;
}
You can click the Inspect button in the index.php page and use Inspect mode to identify the class names by clicking on one of the menu items and looking at the tag selector.
In this part of the series you added a logo, styled your post titles, and added a menu—and previewed all your changes within Dreamweaver. Part 4 of this series covers creating a custom home page for your blog with a custom features box.
Tutorials and samples |
Dreamweaver user forum |
More |
| 04/23/2012 | Resolution/Compatibility/liquid layout |
|---|---|
| 04/20/2012 | using local/testing server with cs5 inserting images look fine in the split screen but do not show |
| 04/18/2012 | Ap Div help |
| 04/23/2012 | Updating |
Dreamweaver Cookbook |
More |