?
Solved

Hardcode wordpress posts

Posted on 2010-11-21
14
Medium Priority
?
427 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
WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

 
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 111

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

WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

Question has a verified solution.

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

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
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 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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

770 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