Solved

Hardcode wordpress posts

Posted on 2010-11-21
14
413 Views
Last Modified: 2012-05-10
Hey Experts!!

I need to hard code 3 specific posts on the home page of a wordpress blog.  However, I'm not sure quite how to do it.  I did try to do the query_posts, but whenever a new post is added it throws it off.  
I was wondering if I can use the 'post__in' => array(5), but not sure how to incorporate it.  I would want to use 3 post ID's total.

Ultimately I only need 3 specific posts on the home page, regardless of new ones that are added.  

Thanks in advance!
<div id="content">	
                <?php if(is_home()) { include (TEMPLATEPATH . '/featured.php'); } ?>
				<?php query_posts('cat=3,941&showposts=3'); ?>
					<?php if (have_posts()) : ?>					
						<?php while (have_posts()) : the_post(); ?>

Open in new window

0
Comment
Question by:LZ1
  • 8
  • 2
  • 2
  • +1
14 Comments
 
LVL 15

Expert Comment

by:AndyBeard
ID: 34183545
The easiest way might be to use sticky posts such as this example

http://www.wpbeginner.com/wp-tutorials/how-to-display-the-latest-sticky-posts-in-wordpress/

Then you have an interface in the standard WordPress to deal with modifications.

0
 
LVL 30

Author Comment

by:LZ1
ID: 34183546
I have 3 posts set to sticky.  The problem becomes that when another post is added, regardless of the category it goes on the front page.  

I really only want 3 hand-selected posts on the front page
0
 
LVL 15

Expert Comment

by:AndyBeard
ID: 34183869
Are you using a custom template or have you limited the number of posts that show on the home page?

I have been using this plugin for this for years
http://moshublog.com/2007/10/30/custom-query-string-reloaded-for-wordpress-23-with-tag-support/



0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 30

Author Comment

by:LZ1
ID: 34184608
Not really custom, but I want to make it custom.

I saw the plugin, however I just want this on the home page and want to be able to hard code it.  The plugin seems to put it on all pages.

All I'm looking for is the PHP query syntax for that part.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 34189267
Here is what I might do.  Go to the pages you want to display.  Copy the fully-qualified URLs out of the browser address bar.  Make links from them and plug the links into your template.  Easy!
0
 
LVL 30

Author Comment

by:LZ1
ID: 34191534
Hi Ray. I thought about it, but for times sake, I'd like to be able to go in there and just add  the PHP

'post__in' => array(5) with the post ID's.  I'm just not sure what the correct syntax is.
0
 
LVL 30

Author Comment

by:LZ1
ID: 34193394
Ray, how can I do what your suggesting?  This can't be that difficult.
0
 
LVL 8

Expert Comment

by:Sam Cohen
ID: 34223668
You can just set those posts as a category Named "featured"
and have the loop select only that category post to show

 
<?php query_posts('category_name=featured&showposts=3'); ?>
<?php while (have_posts()) : the_post(); ?>

// ADD php or html code here if you want

<?php endwhile;?>
0
 
LVL 30

Author Comment

by:LZ1
ID: 34223757
Hi all4artz!
Unfortunately I can't use categories because the featured slider needs an image and I don't want duplicate images on the home page. So I have separate posts for the featured slider and for the actual posts.
That's the main reason for the post id's rather than the category query.
0
 
LVL 8

Expert Comment

by:Sam Cohen
ID: 34223785
not quite understanding....

What is your code??
0
 
LVL 30

Author Comment

by:LZ1
ID: 34223797
I want to show 3 posts via querying the post ID's.  I'm just not sure how to do that with the post ID's.  
I got the following code from the Wordpress codex.

query_posts( array( 'post_type' => array('post', 'movie') ) );

http://codex.wordpress.org/Function_Reference/query_posts
0
 
LVL 30

Accepted Solution

by:
LZ1 earned 0 total points
ID: 34258629
Unfortunately none of the solutions provided worked.  I ended up just using the HTML from the rendered page and inserting it into my main index template.
0
 
LVL 30

Author Closing Comment

by:LZ1
ID: 34289835
Unfortunately none of the solutions provided worked.  I ended up just using the HTML from the rendered page and inserting it into my main index template.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

WordPress is constantly evolving, and with each evolution appears to get better and better.  One of the big drawbacks prior to version 3 was that there was no way to be able to set up a custom menu from the backend. The Old Way Adding menus is…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question