wordpress CMS and query_posts() hacks
How Important query_posts()to develop a CMS with wordpress!
I have convert Wordpress many time into a CMS, not just display pages and remove blog on home page and add some hack in side bar. more than these guys
So i have used this magic wind query_posts() many times, i must say wihtout query_posts() convert into CMS is just a toughest job or you have to do lot of coding hard coded, Hard coded means: html in dyanmic system. which is i dont like at all, owners use wordpress to do all thing dynamically not hard coded. so query_posts() is important a lot. now come on point, users dont have time to read my stupid talks
so go ahead and see some hacks.
1. display particular page into side bar or any other place like home page ?? into a box
<?php query_posts(’page_id=1′); //retrieves page 1 only ?>
<?php query_posts(’pagename=about’); //retrieves the about page only ?>
<?php query_posts(’pagename=parent/child’); // retrieve the child page of a parent ?>
Example to display 3 pages into boxes on home page
i have done that on a recently develop CMS, it display 3 boxes on home page with some contents, here we go what i have done on coding and css
PHP coding —-
1st Box
<?php
query_posts(’page_id=1′);
?>
<div id=”homebox”>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?><div class=”post” id=”post-<?php the_ID(); ?>”>
<h2><?php the_title(); ?></h2>
<div class=”entry”>
<?php the_content(’<p class=”serif”>Read the rest of this page »</p>’); ?><?php wp_link_pages(array(’before’ => ‘<p><strong>Pages:</strong> ‘, ‘after’ => ‘</p>’, ‘next_or_number’ => ‘number’)); ?>
</div>
</div>
<?php endwhile; endif; ?>
<?php edit_post_link(’Edit this entry.’, ‘<p>’, ‘</p>’); ?>
</div>
2nd Box
<?php
query_posts(’page_id=2′);
?>
<div id=”homebox”>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?><div class=”post” id=”post-<?php the_ID(); ?>”>
<h2><?php the_title(); ?></h2>
<div class=”entry”>
<?php the_content(’<p class=”serif”>Read the rest of this page »</p>’); ?><?php wp_link_pages(array(’before’ => ‘<p><strong>Pages:</strong> ‘, ‘after’ => ‘</p>’, ‘next_or_number’ => ‘number’)); ?>
</div>
</div>
<?php endwhile; endif; ?>
<?php edit_post_link(’Edit this entry.’, ‘<p>’, ‘</p>’); ?>
</div>
3rd Box
<?php
query_posts(’page_id=3′);
?>
<div id=”homebox”>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?><div class=”post” id=”post-<?php the_ID(); ?>”>
<h2><?php the_title(); ?></h2>
<div class=”entry”>
<?php the_content(’<p class=”serif”>Read the rest of this page »</p>’); ?><?php wp_link_pages(array(’before’ => ‘<p><strong>Pages:</strong> ‘, ‘after’ => ‘</p>’, ‘next_or_number’ => ‘number’)); ?>
</div>
</div>
<?php endwhile; endif; ?>
<?php edit_post_link(’Edit this entry.’, ‘<p>’, ‘</p>’); ?>
</div>
CSSÂ setting —
#homebox {
float:left;
width:252px;
border-right:1px solid #cccccc;
}#homebox1 {
float:left;
width:253px;
border-right:1px solid #cccccc;}
#homebox2 {
float:left;
width:252px;
}
#homebox .entry, #homebox1 .entry, #homebox2 .entry{
background:#F5F5F5;
width:211px;
text-align:left;
padding:10px;
margin-left:10px;
}
#homebox .entry a, #homebox1 .entry a, #homebox2 .entry a{
color:#C22218;
}
#homebox h2, #homebox1 h2, #homebox2 H2 {
font-size:17px;
}













May 12th, 2009 at 8:45 pm
can i make some thing like a loop to generate the page id instead of writing every page id and it’s code??
May 28th, 2009 at 12:33 am
Please, can you PM me and tell me few more thinks about this, I am really fan of your blog…
June 29th, 2009 at 11:01 am
Interesting post, just signed up to your RSS feed, hope to find some more great content here
November 17th, 2009 at 11:51 am
I am working on some template right now, and I have problem with query posts funciton. I am getting a page and I want only the part before “more” tag, to be displayed. I set the global $more; and more=0; but still I am getting full page instead of lead-in…
November 17th, 2009 at 11:54 am
<!–<a href=”">–>o Nas<!––>
<a href=”"
this is the code I am having problem with…
January 21st, 2010 at 12:44 am
Boo!!
May 16th, 2010 at 8:15 pm
I really need to add its in my brose. Thx u a lot
October 29th, 2010 at 10:21 pm
Maybe you could change the blog name title wordpress CMS and query_posts() hacks,Wordpress Hack-css gallery, css scripts showcase, Iphone gallery, Twitter tricks, php scripts,ajax scripts, Twitter API help, examples, CMS Drupal,CMS Joomla,CMS WordPress:W3CGallery.com to more suited for your content you create. I enjoyed the blog post nevertheless.
March 30th, 2011 at 3:33 am
Perfect just what I needed