WordPress was originally created as a weblog or blog platform. Just now WordPress has grown and then powerful that you tin can apply it to create whatsoever type of website and utilise information technology as a Content Direction Organisation (CMS). In this commodity, I'1000 going to share some of my WordPress tricks with you on how to make a ameliorate WordPress theme. I'chiliad not a programmer nor developer, so I will focus more on the frontend development. Oh yeah, I forgot to mention that WordPress has made it so easy that even a non-programmer (designer like me) can build a wonderful website. My WordPress sites included: N.Design Studio, Best Web Gallery, Web Designer Wall, and some free WordPress Themes.
WordPress Conditional Tags
Conditional Tags are very useful when creating a dynamic WordPress theme. It allows you to control what content is displayed and how that content is displayed. Here are couple sample uses of Conditional Tags:
Dynamic Highlight Carte
Here is what I used to create a dynamic highlight menu on All-time Web Gallery. In the first list detail, if it is Home or Category or Archive or Search or Single, add together class="current" to the <li> tag, which will highlight the "Gallery" button. Second item, if it is page with Page Slug "about", add course="electric current".
<ul id="nav"> <li<?php if ( is_home() || is_category() || is_archive() || is_search() || is_single() || is_date() ) { repeat ' class="current"'; } ?>><a href="#">Gallery</a></li> <li<?php if ( is_page('about') ) { echo ' class="current"'; } ?>><a href="#">Near</a></li> <li<?php if ( is_page('submit') ) { echo ' course="current"'; } ?>><a href="#">Submit</a></li> </ul> Dynamic Title tag
Again, I use Conditational Tags to output dynamic <title> tag in the header.php.
<title> <?php if (is_home()) { repeat bloginfo('name'); } elseif (is_404()) { echo '404 Non Plant'; } elseif (is_category()) { echo 'Category:'; wp_title(''); } elseif (is_search()) { repeat 'Search Results'; } elseif ( is_day() || is_month() || is_year() ) { echo 'Archives:'; wp_title(''); } else { echo wp_title(''); } ?> </title> Dynamic Content
If you lot want to include a file that will only announced on the frontpage, here is the code:
<?php if ( is_home() ) { include ('file.php'); } ?> Characteristic post highlighting
Let's say categoryID 2 is your Feature category and y'all want to add together a CSS class to highlight all posts that are in Feature, you lot tin utilize the following snippet in The Loop.
<?php if ( in_category('2') ) { echo ('class="feature"'); } ?> Unique Unmarried template
Suppose you want to use different Single template to display private postal service in sure category. You lot can use the in_category to check what category is the postal service stored in then utilize dissimilar Single template. In your default single.php, enter the lawmaking below. If the post is in category one, apply single1.php, elseif in category 2, utilise single2.php, otherwise use single_other.php.
<?php $post = $wp_query- >post; if ( in_category('1') ) { include(TEMPLATEPATH . '/single1.php'); } elseif ( in_category('2') ) { include(TEMPLATEPATH . '/single2.php'); } else { include(TEMPLATEPATH . '/single_other.php'); } ? > Unique Category template
Suppose you want to use different Category template to brandish specific category. Just save your Category template as category-2.php (note: add "-" and the categoryID number to the file name). So, category-2.php will be used to display categoryID ii, category-3.php will be used for categoryID 3, and then on.
Display Google Advertisement later on the first post
A lot of people have asked me for this. How to display a Google ad after the first post? It is very simple. Yous merely need to add a variable ($loopcounter) in The Loop. If the $loopcounter is less than or equal to 1, then include google-ad.php code.
<?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); $loopcounter++; ?> // the loop stuffs <?php if ($loopcounter <= 1) { include (TEMPLATEPATH . '/ad.php'); } ?> <?php endwhile; ?> <?php else : ?> <?php endif; ?> Query Posts
You tin use query_posts to command which posts to show upwardly in The Loop. It allows you to control what content to display, where to display, and how to display it. You tin query or exclude specific categories, and so y'all become full control of it. Here I will bear witness you how to use query_posts to display a list of Latest Posts, Feature Posts, and how to exclude specific category.
Display Latest Posts
The following code will output the 5 latest posts in a list:
<?php query_posts('showposts=5'); ?> <ul> <?php while (have_posts()) : the_post(); ?> <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li> <?php endwhile;?> </ul> Display Feature Posts
Let's say categoryID 2 is your Feature category and you lot desire to brandish 5 Characteristic posts in the sidebar, put this in your sidebar.php:
<?php query_posts('cat=2&showposts=v'); ?> <ul> <?php while (have_posts()) : the_post(); ?> <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li> <?php endwhile;?> </ul> Exclude specific category
You lot tin also utilize query_posts to exclude specific category being displayed. The following code will exclude all posts in categoryID 2 (note: in that location is a minus sign earlier the ID number):
<?php query_posts('true cat=-2'); ?> <?php while (have_posts()) : the_post(); ?> //the loop here <?php endwhile;?> Tips: you tin overwrite the posts per page setting by using posts_per_page parameter (ie. <?php query_posts('posts_per_page=vi'); ?>)
Custom Fields
Custom field is one the almost powerful WordPress features. It allows you to adhere extra data or text to the post along with the content and excerpt. With Custom Fields, you tin can literally trun a WordPress into any web portal CMS. On Web Designer Wall, I utilise Custom Field to display the commodity image and link it to the post.
First add the Custom Field in the post.
To display the article image and attach information technology with the post link, put the following code in The Loop:
<?php //get article_image (custom field) ?> <?php $image = get_post_meta($post->ID, 'article_image', true); ?> <a href="<?php the_permalink() ?>"><img src="<?php echo $image; ?>" alt="<?php the_title(); ?>" /></a> Tips: don't forget WordPress allows you to create/store multi keys and the keys can be used more once per post.
I used the same methodology and created a very dynamic template at All-time Web Gallery, where I used Custom Fields to display the site thumbnail, tooltip image, and URL.
WP List Pages
Template tag wp_list_pages is commonly used to display a list of WP Pages in the header and sidebar for navigation purpose. Hither I will show yous how to use wp_list_pages to brandish a sitemap and sub-menu.
Site map
To generate a sitemap (sample) of all your Pages, put this code in your sitemap Page Template (annotation: I exclude pageID 12 because page12 is my sitemap folio and I don't want to show it):
<ul> <?php wp_list_pages('exclude=12&title_li=' ); ?> </ul> Dynamic Subpage Menu
Put this in your sidebar.php and information technology will output a subpage menu if there are subpages of the current page:
<?php $children = wp_list_pages('title_li=&child_of='.$mail service->ID.'&echo=0'); if ($children) { ?> <ul> <?php echo $children; ?> </ul> <?php } ?> Page Template
If you are using WordPress equally a basic webpage management, you better don't miss out the Page Template feature. Information technology allows you to customize how the Pages should exist displayed. To use Folio Template, first you need to create a Page Template, and so you can assign the Page to specific template.
Here is how the Page Template structured (ie. portfolio.php):
<?php /* Template Proper noun: Portfolio */ ?> <?php get_header(); ?> //the loop here <?php get_footer(); ?> When you are writing or editing a page, look on the right tab "Folio Template" and you should see the available templates.
WordPress Options
In that location are many built-in options in the Admin panels that can brand your site much nicer. Here are some of them:
Custom Frontpage
By default, WordPress displays your blog posts on the frontpage. Merely if you lot want to have a static page (ie. welcome or splash page) instead, yous can set that in Admin > Options > Reading.
Permalinks
Default WordPress uses www.yoursite.com/?p=123 for your post URLs, which is not URL nor search engine friendly. You can change the Permalinks setting through Admin > Options > Permalinks. Personally, I like to prepare the Permalinks to: /%category%/%postname%/
Category prefix
Default WordPress category prefix is "category" (ie. yoursite.com/category/cat-proper name/). By entering "article" in the Category base (Options > Permalinks), your category URLs volition go: yoursite.com/commodity/cat-proper name/
Want more than?
WordPress Codex is always the best identify to learn about WordPress. Thank you WordPress and happy blogging!
DOWNLOAD HERE
Posted by: putmanclearders.blogspot.com
Postar um comentário