Solved

Hardcode wordpress posts

Posted on 2010-11-21
14
395 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In Part I (http://www.experts-exchange.com/Web_Development/Blogs/WordPress/A_8410-Getting-Started-In-WordPress-Part-I.html), I introduced you to the powerful WordPress backend, the WordPress administrative Dashboard.  In Part II, I will introduce yo…
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 update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

706 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

20 Experts available now in Live!

Get 1:1 Help Now