Solved

Hardcode wordpress posts

Posted on 2010-11-21
14
418 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
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 110

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The viewer will learn how to count occurrences of each item in an array.

739 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