Thank you for your hand health
After a short break of writing on WordPress and on the request of my subscribers i decided to make a list of useful WordPress tricks and you are probably already using some of them, if not going to when making a WordPress theme. As you already know WordPress is one of the most popular blog platforms these days and it has grown so powerful that you can use it also use as Content Management System (CMS).
If you are new to WordPress and blogging itself you should read "Before you start blogging" article and go with some free themes for now, which you can find here in free themes directory.
<?php $category = get_the_category(); echo $category[0]->cat_name; ?>
So this grabs a single category name (it's not printing it just keeps it for now) and I've been using it a lot while developing themes
<?php /* Template Name: Free Themes */ ?> <?php get_header(); ?> //the loop <?php get_footer(); ?>
You should be familiar with this it makes a custom page template which you have to assign to some page after creating it. I've written a bit of it on how to make a archive page article and you can read more about it here
With query_posts()
<?php query_posts('cat=3&showposts=1'); ?> <?php while (have_posts()) : the_post(); ?> <?php the_excerpt('Read the rest of this entry »'); ?> <?php endwhile; ?>
query_posts() is very useful and you can use it where ever you want, display latest posts (<?query_posts('showposts=10');?>) for example or client testimonials, exclude a specific category (<?php query_posts('cat=-3'); ?>) etc...
With new WP_Query()
<?php $recent = new WP_Query("page_id=2&showposts=1"); while($recent->have_posts()) : $recent->the_post();?> <?php the_excerpt('Read the rest of this entry »'); ?> <?php endwhile; ?>
You'll notice these two are very similar so what ever you feel like using, i personally use the first one links and the second one for content. I've used it in my "Tabbed Featured Post" tutorial, click here to see how it looks like.
The php solution
<?php $i=1; ?> <?php while (have_posts()) : the_post(); ?> <?php if ($i == 1) { ?> <div id="post-<?php the_ID(); ?>" class="featured"> featured content </div> <?php } else { ?> <div id="post-<?php the_ID(); ?>"> rest of content </div> <!-- post --> <?php } ?> <?php $i++; ?> <?php endwhile; ?>
I think it's pretty much clear, it changed first post into a different div style (you can use here what ever you want of course). I've used this in my Solemnity free WordPress theme and if you would like to see how it looks click here for demo page. The only thing i don't like about this way is that your main loop in this case has to be in seperate div, you know you can't have anything between featured post and rest of posts (for example sidebar etc...) like here on Stylized Web. So becarefull how you will code it into html first
<?php include (TEMPLATEPATH . '/sidebar2.php'); ?>
If you need to include some other file than <?php get_sidebar(); ?> for example different sidebar or footer file etc...
<?php if ( is_front_page() ) { include (TEMPLATEPATH . '/home1.php'); } else { include (TEMPLATEPATH . '/rest.php'); } ?>
Don't think it needs some explanation, this also could be used for featured content/post and here are some other Conditional Tags:
is_home(), is_category(), is_archive(), is_search(), is_single(), is_date(), is_404(), etc...
In your index.php file, look for this bit of code: <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?> Right before that line, add this code: <?php query_posts($query_string . “&order=ASC”) ?>
If you are the old-fashion guy and like the old ones on the top
Bad code used in title tags or search templates: <?php echo $s; ?> as it allows malicious code injection. You should use this one <?php echo wp_specialchars($s, 1); ?>
<?php $comments = array_reverse($comments, true); ?> <?php foreach ($comments as $comment) : ?> content here <?php endforeach; ?>
<?php $posts=query_posts($query_string . 'posts_per_page=10&offset=2'); while (have_posts()) : the_post(); ?> this will exclude first two posts <?php endwhile; ?>
Have some feedback? Leave a commentThank you for your hand health
This is awesome, I wanted to make a simple theme with a featured post section and the rest of the posts neatly lined under it! Thanks heaps!
thanks you
You will have to crawl very nice,owe you gratitude..
thnx for this good articles
thaks for admin wanderfull blog
thank you everybody .This very important blog
Thanx You Admin or Usher’s Very Good post is :
very nice is post good thanx
Looking for a solution was. Thank you everyone who labor.
im getting wp-commecnts blank?
Been using some of them for long time now, good to see them in one place
I’ve always believed that the best flash sites are the ones where I have to right-click just to see if it’s actually flash. Not to decry full-flash sites or anything, but I hate having to skip an intro, or watch some stupid tween that was already long-cheesy when I learned to do it way back in high school with Flash 5, or turn off the music.
That said, as a developer I’ve rarely used it, and I’m intrigued by some of the examples you’ve given. I don’t suppose you have a favorite reference you’d like to tell me about.
Really cool list. thank you. (no wonder this post is at the top on search results
)
Thanks For Information’s
thaks for admin what ı need ı take
Thank’s Administrator
I have tried the “reverse post order” on my theme, and it doesnt appear to work. Is there something simple you can think of that I can do in the stylesheet to allow this bit of code to work, or would it be something complicated with multiple adjustments?
I wanted to archive my blog (I use it to write fictional stories) and now that it is not running “live” it would be much easier to read if it ran in reverse order.
Thanks for your time. Great tips, by the way.
reel life web site
good joop
everthing its true
reely good web site
good blog what ı need ı see..thaks for admin
it is very god blog ,thanks
thank for admin
thanksss
tahnkss for all
Thanks. Big list. Bookmarked!
thansk for all
Subscribe To Comments – Allows readers to receive notifications of new comments that are posted to an entry. Essential to help encourage commentors to return whenever a new comment has been added to the post that they have previously commented
barkod sistemi
barkod okuyucu
barkod yazıcı
Thank you very much for everything
Привет. Возникла проблема – прикупил я электродрель на магазин ру
А она сломалась у меня в тот же день – гарантии практически никакой не дали. Просто почта пришла с коробкой, а там все на китайском. Написал в магазин этот, дали ответ, что обращайтесь в сервис центр, хотя у меня ни документов на руках нет, ничего. Как возможно приструнить этот интернет магазин? Есть ли какие-то компетентные органы, что писать. Куда писать, кому писать. Сделал ошибку, да, надо было в торговом центре нормальном прикупить, но нужной мне модели просто не было, да и дешевле в интернет-магазине. А вот теперь сижу у разбитого корыта. Подскажите, что делать.
thanks for the sharing.
usefull tricks this are for my blog how i can show only one cat. in sidebar?
There is some great and useful code in this batch. This is a helpful reference for our WordPress customization work. Appreciated.
İt is good
INTERFERENCE FOREIGN TRADE web environment
We offer all products with the best service initiatives, improving the quality of service the products you ihtal web environment provides a detailed way. Category dedicated to the product range with the desired structure, providing convenient access to products from our web site to review the order or request for information from the contact form to reach us
Thanks for posting about this
Thank you i ll think maybe i can themes
Thanks for posting about this, I would like to read more about this topic.
Fore Kazık, Kazık Makinası, BEKSAL ZEMİN, Sağlıklı yapılar için Fore Kazıklama sitemleri şarttır.
Very useful, thanks. I specially liked the tabbed script.
Wow! Really good work.Thank You.
thank you administratör
thanks very googd thank you admins
Hi, WordPress 2.8 is come out, do all the tips work?
Thanks
Thanks you
thanks for code
good article thanks
good idea thanks man.
good work thank you .
This for wordpres ?
thanks for share !
great sharing thans !
thanks C*
INTERFERENCE FOREIGN TRADE web environment
We offer all products with the best service initiatives, improving the quality of service the products you ihtal web environment provides a detailed way. Category dedicated to the product range with the desired structure, providing convenient access to products from our web site to review the order or request for information from the contact form to reach us
Play Free Online Games, sports games, massive multiplayer games, action games, puzzle games, flash games and more, casual games.
thank
Very useful, Im thinking about getting wordpress for my website soon
thanks for tutorials
thanks
heyy..
i copy this enty to my blog…
but dun worry..
i put your link in this entry
nice, really nice!
great article thanks
Bookmarked ! thank you.
good article,
thanks a lot
really good article
have a nice day
Chris
Great nice
Great nice
Turkisch free mp3 download.
thanks
it was useful. thanks
thank you
thank you
thank you
thank you
thank you
thank you
thank you
thank you
thank you
really good article
have a nice day
Chris
Thanks. Good news
thanks good article.
thank u…
i will test it..but still i dont understand … Thank you for sharing!!
perceft global hot=)
It’s very good article. Great site with very good look and perfect information
thankss
nice tricks
it’s awesome! thanks for all
thanks for you..!
thank you
good wp plugin
Great sharing thanks….
Thanks man
Global chat sites
i use somethings
ohhh!
yes thanks admin for sharing
Thanks
thanks….
nice site thank you admin.
Thanks it is great !
Thanks for all code
thanks a lot
thanks man
thnk u mn
Thanks for sharing these solutions, and congrats for your blog design
thanks I search this code thnks
I was finding about css codes when I discovered this site. Congratulations for this website, It’s very useful and instructive. A lot of thanks!!
Thanks for sharing these solutions, and congrats for your blog design
i search this thing for my website thnks
Админчег
У меня к тебе небольшое предложение, хоть и не по теме блога
Напиши пожалуйста свой обзор передачи Гордон Кихот. Особенно прошлый выпуск, про Шансон.
Спасибо
Удачи дружище
Thanks Dejan.
thanks a lot for sharing. Good luck for you
cool .. thank you for post.
Thank you.
Thank You. great trick…
Really nice set of tricks for WP. Thx!
I would like to know, would htmlentities() instead of wp_specialchars() work fine too?
Thanks for sharing these solutions, and congrats for your blog design.
Great article?
You mentioned you using query_posts() for grabing links..
How do you grab a specific link category and display those links in the footer?
Nice Article
Thanks you very much
Cezar,
please give us a more detailed explanation,tell us what part of this article are you referring to and past your code here
great trick,
i have one question though. why cant i get the tags to show.
i added in the loop but they dont show. are they supposed not to work? or am i doing something wrong?
thanks,
C
you are welcome
Dejan Cancarevic “Max,
Try this http://stylizedweb.com/2008/03/01/syntax-highlighter/“
Thanks for the link!
you can find it here
http://stylizedweb.com/2008/06/20/grab-data-from-wordpress-database/
You, my friend, are a champion! I know this might be pushing the envelope, but WP_Query() is restricted to posts, or can I get a list of recent comments too in a similar way?
Harley,
Sure it is, use WP_Query() as i says in text, so try this
<?php $recent = new WP_Query(“showposts=5″); while($recent->have_posts()) : $recent->the_post();?>
<li><a href=”<?php the_permalink() ? rel=”nofollow”>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”><?php the_title(); ?></a></li>
<?php endwhile; ?>
Hey, I’m just having a bit of trouble with the query_posts():
I want to know if it’s possible to have such content needed (I need a list of post titles) BEFORE the main loop? I have a section in my header that I wanted to include recent posts in (without using a plugin), however when I use the exampled ‘query_posts() code, it shows what I want up top in the header, but then the content in the main loop is whatever was specified in the query_posts(), which for example was just the 1 post from a certain category.
Is it possible to ‘end’ the use of the query_posts() for the header only? When I pasted the code AFTER my main loop, it worked! I’m confused as to why this is so, maybe you could shed some light on it for me!
Thanks a lot, and fantastic post by the way. Learnt some cool stuff!
~Harley
Max,
Try this http://stylizedweb.com/2008/03/01/syntax-highlighter/
Thanks for the post! Helped me a lot.
Just a side-question, how did you get the code displayed? What plugin? Thanks
Max
really cool tips thanks!
Karen,
go ahead and post your question to
http://stylizedweb.com/knowhow
Dejan, nice job! I’m new to Wordpress (& am not a template designer) . .. am wondering how I can change the link text color from white to black? The white just doesn’t show up very well . . . I’m using the Sweet Sunset Wordpress Theme. Thanks for any help you can give!
Very useful tips, thanks, Dejan!
Thanks for sharing these solutions, and congrats for your blog design.
All,
Thank you for the good words, i really appreciate it!
Thanks Dejan ::)
Woot! Congrats!
i come from chinese, and i like your design. i have use it in my second blog, thanks, it look great.
Awesome site!
This are all some pretty useful tips. I am going to add a link to this post and your site on my blog.
Cool. I’m gonna use these!
thanks for this good article..
Really nice set of tricks for WP. Thx!
Thx, Dejan
These tips are really great.
Bingu,
I’ve updated the post with it
How to reverse comment order?
I would like to know, would htmlentities() instead of wp_specialchars() work fine too?
just wanna touch the include specific files tips for sidebar
if you have additional sidebar like for single or archive you can do it like the following (WP2.5.x)
get_sidebar($name); // arg $name is sidebar-”name”.php
the function will look for sidebar-single.php (inside theme dir) and load it if exists otherwise it will load the default sidebar.php.
you can include section base sidebar base on wordpress hierarchical order. below is just a simple example (need to tweak it base on which section came first thought)
if (is_single()){
get_sidebar(’single’); // include /theme/sidebar-single.php
} elseif (is_archive()){
get_sidebar(‘archive’); // include /theme/sidebar-archive.php
} else {
get_sidebar();
}
Hey, WP cut off my code!
Here’s the code: http://paste.ubuntu.com/20100/
heh yea sorry i hate when WordPress does this..
Thanks Dejan.
Only a correction:
<a class="continuelink" href="" rel="nofollow" title="Continue reading ">… continue reading
johnbillion,
thanks i didn’t know about that one
Teli Adlam ,
I’ve been using is_home for a while now so thanks for the heads up!
Thanks for the tricks. Stumbled. Will come handy anytime.
great infos about wp!
Nice write up. Picked up a few ideas for use in future themes, so thanks for taking the time to compile it.
You may want to add a note about is_home as it’s been slightly tweaked for version 2.1.x and up. (Basically, is_page(‘home’) seems to be the preferred conditional tag when working with newer versions of WordPress.)
Dejan,
Instead of wp_specialchars() I use attribute_escape(). There is no difference to the output, but attribute_escape() is preferred as it passes the output through the attribute_escape filter first.
just add manually
<a class=”continuelink” href=”<?php the_permalink(); ? rel=”nofollow”>” title=”Continue reading <?php the_title(); ?>”>… continue reading</a>
Pardon: inside the parenthesis in the_excerpt() there is ‘Read the rest of this entry’
Here’s my code in my sidebar: http://paste.ubuntu.com/20006/
Hvala!
Steven,
Thanks buddy
Aldo,
Go ahead and past your code here and we’ll see what is it
Nice resource for all WP theme designers.
I’m ashamed to admit I’ve never heard the last one before. It’s especially troubling because it’s the one where my ignorance could have negative consequences.
Nice tricks!
I’d like to know why — using ‘The featured post’ — the line ‘Read the rest of this entry’ is not displayed in my sidebar.
Hi,
really good article
have a nice day
Chris
Andrew,
heh i’m glad you like it
If you have some PW issues or questions go ahead and post them b/c that’s how i’ve written this article – people asked questions, so i’ll be happy to help..
Ivan,
I think so too
Been using some of them for long time now, good to see them in one place
Excellent! I can’t tell you how many PHP 101 sites I have had to sift through to get this information (I’m much more a designer than programmer). -If only I would have found this post earlier!
heh i’m not using any of them, shame on me
really useful info, thanks!
on February 8, 2010
Thanks Adminstrator For Dar Gelirli Users…