wordpress CMS and query_posts() hacks


2 Votes, Rating: 51 Star2 Stars3 Stars4 Stars5 Stars

Tags:

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 icon smile wordpress CMS and query posts() hacks

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 icon smile wordpress CMS and query posts() hacks 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 &raquo;</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 &raquo;</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 &raquo;</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;
}

Even you can copy and paste these into your site to see how it works and make change according to your themes or requirements. i have give full codes as some user was asking  me full codes many time. so now you guys will be happy i guess.

Share/Save/Bookmark

9 Responses to “wordpress CMS and query_posts() hacks”

  1. Islam Ahmed says:

    can i make some thing like a loop to generate the page id instead of writing every page id and it’s code??

  2. seo ranking says:

    Please, can you PM me and tell me few more thinks about this, I am really fan of your blog…

  3. Refinancing says:

    Interesting post, just signed up to your RSS feed, hope to find some more great content here :)

  4. mathew says:

    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…

  5. mathew says:

    <!–<a href=”">–>o Nas<!––>
    <a href=”"

    this is the code I am having problem with…

  6. cb affiliate loophole says:

    Boo!!

  7. learn to speak hindi says:

    I really need to add its in my brose. Thx u a lot

  8. Schedule says:

    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.

  9. Brandon says:

    Perfect just what I needed

Leave a Reply