Solved

Hardcode wordpress posts

Posted on 2010-11-21
14
407 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
 
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 108

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to create an extensible mechanism for linked drop downs.
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

914 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now