WP plugin: Get-a-Post

posted on January 27, 2005  (Update: January 27, 2008)

Get-a-Post is a WordPress plugin that allows you specify a post or Page (but just one) to be displayed. This can, for example, let you provide an informational note on your sidebar or front page, or a “static” article at the top of a category page or in a custom template, all the while using standard WordPress template tags to decide how it’s displayed.

To install Get-a-Post, download the zip file, extract get-a-post.php, upload this to your wp-content/plugins/ directory, and activate the plugin.

Usage

<?php get_a_post(id); ?>

Place the get_a_post()tag in your template where you want a post/Page to appear, then right after it any template tags you desire to use, as long as they are specific to The Loop (see examples below).

Parameter

id
Either the numeric ID for a post or Page (format: 10 or '10') or it’s postname i.e. Post/Page slug (format: 'post-or-page-title'). Certain defined id options can be used to collect certain types of posts/Pages:

'GETPOST' (or leave parameter empty) – Latest post.
'GETPAGE' – Latest Page.
'GETSTICKY' – (Latest) post or Page with a custom field key of ‘sticky‘ and a value of ‘1‘.
'GETRANDOM' – A random post.

Examples:

<?php get_a_post(123); ?>
    <h3><?php the_title(); ?></h3>
    <?php the_content(); ?>

Displays the title and content of a post or Page (ID #123). Useful as a welcome message in the sidebar. Placed above The Loop, it will appear as the first entry.

<?php if(is_category(1)) : ?>
<?php get_a_post(10); ?>
    <p>A message from <?php the_author(); ?></p>
    <?php the_content(); ?>
<?php endif; ?>

Displays “A message from POST AUTHOR” and content of a post or Page (ID #10) if on the category page for category #1 (tests for this in an if statement using the WordPress 1.5 conditional function is_category()).

<?php get_a_post('about'); ?>
    <h3><?php the_title(); ?></h3>
    <p><?php the_content_rss('', 0, '', 50); ?>
    <a href="<?php the_permalink(); ?>">read more</a></p>

Displays the title and content of a post or Page (Post/Page slug ‘about’); the content is abbreviated to 50 words using the the_content_rss and its ‘cut’ parameter, and then links to the Page itself (using “read more” for link text).

Update [Jan-27-2008]: R1.4 Adds a 'GETRANDOM' id, which retrieves (surprise!) a random published post (but as always, just one).
Update [Apr-21-2006]: R1.3 Fixes a bug (see numerous comments below—sorry everyone!). Also slipped in the 'GETSTICKY' id, which displays any post or Page (but again, just one) you add a custom field key of ‘sticky’ and value of ’1′ to.
Update [Mar-03-2006]: R1.2 now defaults to the latest (last published) post or Page. Use 'GETPAGE' (all caps) as argument for latest Page, and 'GETPOST' or no argument for latest post. I’ve also slipped in tentative suppport for the next update to WordPress (currently referred to as 2.1). May be the first plugin to do so…
Update [May-04-2005]: R1.1 caches post-meta (custom field) data in a post or Page to use with other plugins or template tags. Slight changes to code, including explicit GPL licensing.
Update [Mar-01-2005]: Now finally at R1 (Release 1) since I can’t seem to break it, Get-a-Post has been updated to handle Pages in WordPress 1.5. It also accepts a postname (Post/Page slug) as well as the numeric ID for the post/Page you’re calling. All information above (with additional examples) reflects these changes.
Update [Jan-29-2005]: Sometimes you just need to make things easier. Get-a-Post, now at version 0.3, provides a far simpler method of using it within your template. Example above reflects the update.
Update [Jan-28-2005]: Because of changes in how the next version of WordPress (1.5) handles processing of The Loop, I’ve made a small mod to Get-a-Post (now version 0.2). This doesn’t change functionality, but does simplify The Loop one now uses for it (see Jan 29 update).

Author: Kaf Oseo
Categories: WordPress
Comments: (141) · Leave a comment · Comments RSS2

clint
Comment » February 26, 2005 @ 10:31 pm

hey kafkaesqui, came across this plugin tonite and gonna give it a try..I came first for your last edited plug, installed that on a site im workin on and it works great!

Denis de Bernardy
Comment » March 24, 2005 @ 8:31 pm

{{{{{Kafkaesquí}}}}}

Kaf
Comment » March 24, 2005 @ 9:56 pm

“Bracket my name all you want, but you’ll never box me in!”

I wonder if that’s a famous quote…

Paul van Iterson
Comment » April 3, 2005 @ 8:57 am

Wouw, very nice script. Love it :D Use it on my website now.. Keep it up!!

Andreas
Comment » April 20, 2005 @ 9:13 pm

This is useful! I have the same functionality on my site, but it is a very strange solution based on conditional tags. This seems a lot easier to work with. Will try it later, thanks!

Peter
Comment » May 1, 2005 @ 9:51 pm

Hi, is there a way to get a second and third and much more posts on one page .
Becouse i hane a problem i can inser only one…?

Thanks

Kaf
Comment » May 4, 2005 @ 1:23 am

Peter, if your question is specifically about Get-a-Post, then all you need do is use <?php get_a_post(#); ?> (# = post ID) again in your template to display an additional post. Use it three times to get three posts, and so on.

LiZharD
Comment » September 9, 2005 @ 10:42 am

It works with conventional PHP if statement?
I’ve tried with:

LiZharD
Comment » September 9, 2005 @ 10:44 am

php if(is_page(’24′) && $splitpage ==”2″) : ?>
php get_a_post(5); ?>
php the_content(); ?>
php endif; ?>

(sorry for double comment)

Patrice Miller
Comment » October 7, 2005 @ 2:18 pm

Really great plugin! I had a problem maintaining our group blog because if editing the main page but with your plugin, it makes my job easier! Thanks and more power to you!

Chris Bose
Comment » October 11, 2005 @ 5:48 am

Very good plugin; but appears to break in IE6 on the PC when used on the index page. I used a standard WordPress install. Everything looks OK on a Mac Firefox, IE, Safari, but on a PC all the sidebar formatting is lost. Take the code out of the index page and everything looks right again. Have you noticed this?

ldp
Comment » November 3, 2005 @ 11:16 am

hi.
i saw your comment on a topic i made on wordpress.org/support.

its a great plugin, but it’s not what im looking for.
(i’m talking about multiple post in the front page of just one category.)

ravi
Comment » November 8, 2005 @ 4:27 pm

I am having these warnings after activiating it (Ver. 1.5.2):
Warning: Cannot modify header information - headers already sent by (output started at /home/.ankelfraeseren/friendklay/ravichhabra.net/wp-content/plugins/get-a-post.php:58) in /home/.ankelfraeseren/friendklay/ravichhabra.net/wp-admin/admin.php on line 10

Warning: Cannot modify header information - headers already sent by (output started at /home/.ankelfraeseren/friendklay/ravichhabra.net/wp-content/plugins/get-a-post.php:58) in /home/.ankelfraeseren/friendklay/ravichhabra.net/wp-admin/admin.php on line 11

Warning: Cannot modify header information - headers already sent by (output started at /home/.ankelfraeseren/friendklay/ravichhabra.net/wp-content/plugins/get-a-post.php:58) in /home/.ankelfraeseren/friendklay/ravichhabra.net/wp-admin/admin.php on line 12

Warning: Cannot modify header information - headers already sent by (output started at /home/.ankelfraeseren/friendklay/ravichhabra.net/wp-content/plugins/get-a-post.php:58) in /home/.ankelfraeseren/friendklay/ravichhabra.net/wp-admin/admin.php on line 13

Spiff
Comment » November 24, 2005 @ 11:54 am

Thanks, just what i have been looking for to show some author info in the sidebar. It’s simple and it works.

dojng
Comment » December 22, 2005 @ 4:41 pm

if id would default to the last post, this plug would be perfect for me.

Kaf
Comment » January 1, 2006 @ 10:24 pm

Good suggestion, dojng. I’ll update Get-a-Post so it defaults to latest post or Page (I’ll set a special argument so the function knows which one) once my “2.0″ updates to a few other plugins are out.

karl
Comment » February 1, 2006 @ 1:16 am

im new to wp – i really need this pluggin – ive been at it for hours and failing

i want my 1 post ( at bottom ) to appear at the top – can someone please help me:(

http://piercingthedarkness.info/blog/

thank you

David McDonald
Comment » February 14, 2006 @ 12:07 am

If it could take arguments so it could get the latest post, or the last 10 posts without having to insert the code 10 times, that would be helpful.

eyerouge
Comment » February 22, 2006 @ 3:53 am

Excellent. Thanks for the plugin. Have it installed on my site to display a picture in my sidebar that I change once in a while (yeah, I didn’t want random, prefer to choose myself and have it there in periods). You script lets me do that (once installed) without having to edit my sidebar.php file any more.

Kaf
Comment » February 28, 2006 @ 3:16 pm

David McDonald, I like the idea of defaulting to the latest post (or Page), which I note in an earlier comment above. Everyone consider it crayoned in for the next update. However, handling multiple posts is not what this plugin was designed for.

Jon
Comment » March 11, 2006 @ 1:33 pm

I’ve been fiddling with the plug-in for about two hours now and can’t get it to work. I’ve even tried editing the source code to make it work, but no luck. When I insert the function into my template like this:

get_a_post(38);
echo the_ID();

It returns 2 and displays the last page I created, rather than post 38. For the life of me, I can’t figure out why.

I’m using WordPress 1.5.1.3

Help please

Mark Fleming
Comment » March 17, 2006 @ 2:50 pm

Your plugin is returning a different “page” than I am requesting. I sepcify a page id of 12 and it keeps returning a page I have with an ID of 10. I’ve tried with and without single quotes, and I’ve tried other pages, but it always display page ’10′

Too bad, I really wanted to use this.

I’m on R2

Josh
Comment » March 22, 2006 @ 10:37 am

Great plugin, Kaf. What would you think about adding a category option, so you could ‘get a post’ from a specific category, and only that category?

Joe
Comment » March 22, 2006 @ 12:38 pm

Great plugin! Just wanted to second Josh’s request. It would be great to pull out the latest post from a specific category. Any plans for this?

Joe
Comment » March 22, 2006 @ 2:05 pm

Kaf,
Hope you won’t mind, but I decided to do a quick hack job that will pull the latest post only in a specific category.

My hatchet-job is located here:
http://mudbomb.com/images/files/get-a-post.php.txt

It ain’t pretty, but it works in WordPress 2.0. Be sure to set $mycategory = 6; to your category.

btw: Kaf- feel free to salvage anything you can to use in your plugin.

Jennifer
Comment » March 22, 2006 @ 5:22 pm

Not working for me on 2.0.2. Defaulting to last page created. Much sadness.

Rob
Comment » March 23, 2006 @ 9:40 pm

I’m having the same problem as Mark Fleming and Jon above… it does not return the page I specify, rather a completely different page. ‘GETPAGE’ works, but I don’t want the last page created. Can anyone shed some light?

Rob
Comment » March 23, 2006 @ 10:28 pm

Those with my problem (Jon, Mark Fleming, Jennifer)… try putting parentheses around the last $query_suffix string, like this:

$query_suffix = “(post_status = ‘publish’ OR post_status = ‘static’)”;

It worked for me.

pati
Comment » March 24, 2006 @ 8:13 am

@rob – thx a lot for the tip. it helped me with the problem. how long did you search for this detail?!

Rob
Comment » March 24, 2006 @ 8:53 am

Pati – glad it worked for you too. I had been fiddling with the plugin code for about an hour. I narrowed the problem down the &query_suffix string. I wasn’t absolutely certain this one simple change alone actually solved the problem… nice to get confirmation.

Kaf – is this a bug?

Nick
Comment » March 25, 2006 @ 9:43 am

This last solution doesn’t solve my problem. When I put parentheses it gets no post at all. When I do not use them, it gets a completely irrelevant post.

Anybody has other ideas?

Nick
Comment » March 26, 2006 @ 3:24 am

I think the problem is I have WordPress 2.0 installed. Right?

Kaf
Comment » March 26, 2006 @ 12:16 pm

I think the problem is I have WordPress 2.0 installed. Right?

Not if you’re using the recent update. For everyone dealing with this issue, I’ll try to get a fix up here by the end of the day.

Joe, once I deal with this issue of incorrect Pages being displayed, I’ll check out your work.

Nick
Comment » March 28, 2006 @ 4:04 pm

Anything new yet about fixing this issue????

Alex Wx
Comment » April 3, 2006 @ 4:22 pm

I too was having trouble with it retrieving a “random” post; looks like it’s just missing parentheses in the query:

SELECT *
FROM wp_posts
WHERE ID = '10'
AND post_date < = '2006-04-03 14:07:05'
AND post_status = 'publish' OR post_status = 'static'

which returns more than one record. Should be instead:

AND ( post_status = 'publish' OR post_status = 'static' )

I fixed mine (on line 60), seems to work fine for me with numeric or slug IDs on WP 2.0.2
Cheers,
–Alex

chairs
Comment » April 4, 2006 @ 3:30 am

Hi,
There is one same post that I want to be seen on my homepagge from one of the categories. Someone redirect me to your plugin but I am having problems because the instruction is not clear to me. I am a newbie. I uploaded the plugin to my wp-content/plugins/ directory, and activate the plugin. But i don’t know where will I add the code

Can you kindly help me out? There are some posted articles on the homepage already and I only want the same article (#17)to appear on my frontpage. I tried to post the code but i got some error page. Thanks!

skube
Comment » April 17, 2006 @ 11:41 am

I’m using WP1.5.2 and had the same problem where it was getting an irrelevant post. Adding in the parentheses as Rob suggested worked for me.

Brad Bice
Comment » April 18, 2006 @ 9:04 am

I also had to add the parentheses to that last line on my WordPress 2.0.2 installation.

Kaf
Comment » April 21, 2006 @ 2:19 pm

Sorry for the delay on the bug fix everybody. For your patience, I added the new ‘GETSTICKY’ id. See the April 21st update.

jpfieber
Comment » April 28, 2006 @ 8:45 pm

Very useful plugin. I have it working on my setup, but I need it to grab the most recent post from a specific category. I tried the hacked code that Joe posted above, and it does work to show the latest post from the specified category, but in the process it removes the checks for time, so it ends up showing scheduled posts. Any way you can include the ability to specify a category, but not allow scheduled posts to appear?

coxis
Comment » May 22, 2006 @ 4:19 pm

i want to set a sticky post on the top with this plugin
what will be the code for it
thanks for help !!!

Subir Ghosh
Comment » June 3, 2006 @ 1:39 pm

Is there a way I can use it outside the loop?

I have a static front page in that I have removed the loop totally. In different slots I want to call in specific items.

I have been trying this function: but it hasn’t been working:

$posts = get_posts(‘category=63′);
if( $posts ) :
get_a_post(4592);
the_title the_excerpt
endif;

Subir Ghosh
Comment » June 4, 2006 @ 8:36 am

I think I must clarify a bit on my prev msg.

It works fine on the site but on my box every instance of its use is showing up one specific ‘page’ and NOT the particular ‘posts’ that I am calling in different areas of the homepage.

I can’t figure out what can be the reason. The same sets of plugins are active both on the site as well as on my comp.

Could it have something to do with the Options?

There are many ‘pages’ on the site. It is the FIRST page (in terms of post ID) which is showing up in all distinct instances that I am calling “get-a-post”

(Apologies Kaf, for the cross-posting)

Raymond.CC
Comment » June 5, 2006 @ 3:09 am

Is there any demo on what can this plugin do?
Sorry as I can’t really understand the description…

Marc
Comment » June 16, 2006 @ 11:41 am

Very good plugin. Very usefull. It can be use to “include” a text of a different page or post in a post or an article if use in conjonction with EzStatic.
Thank you!

A question: Is that possible to limit (cut) the excerpt to a paragraph (or two) instead of a certain number of words?

Adam
Comment » June 17, 2006 @ 8:29 pm

Hello… great plugin. Just discovered it and it works great. I am using the GETSTICKY plugin on index.php to display a special post at the top of the page in its own div. If I remove the “sticky” keyword and value from the post, the div remains and WP tries to display the postmetadata. I would like for the frontpage to appear normal (as it would without the plugin – most recent posts). That way, the site administrators can decide to just add/remove sticky designations to any post as they please and it will either show the sticky post if there is one available, or show nothing. Is that possible?

Thanks for all your help, and writing some very useful plugins.

Adam

Moises Kirsch
Comment » June 20, 2006 @ 7:39 am

Is there a way to see if there is any content after calling the Get A Post function?

I would like to setup something like an Alert System… if the page (called alerts) has any content display the html… if not, do not display anything at all.

If I can use get a post it would be great… and If I need to modify anything it ok… I’m just looking for the best (and simplest) solution.

Thanks

Hans Chee
Comment » June 24, 2006 @ 12:14 pm

I’ve uploaded the plugin but can’t locate it in my Plugin menu. I’m using WP 2.02, is there something I missed?

I hope this will help me to get the uri of the LATEST “page”, which is what I’m looking for.

Thanks.

Stacker
Comment » August 9, 2006 @ 4:57 pm

Hello
This looks great. Thanks for all your work on this plugin.

I have one question:

I am using this code

Above the title appears ????
Also, above the content appears ????

Do you knw how I can remove these questions marks?

Thanks.

Stacker

arlan
Comment » August 15, 2006 @ 9:13 pm

I’ve tried the plugin and it works and displays the current post, but it ignores “more” . I really don’t want to put a long post in my front page, could anyone suggest a hack?

Jason Cramer
Comment » August 29, 2006 @ 4:53 am

THANK YOU THANK YOU THANK YOU!!

I searched for probably 3 hours for a way to make my custom static home page show just the excerpt of only the most recent post. Your plugin made it a breeze.

To arlan: use the function called the_excerpt(); and it will use the more tag to break it off or else only allow a preset number of words. I’m sure you can come up with a good way for showing the “read more” permalink.

ali
Comment » September 18, 2006 @ 11:52 pm

thank you for this one. it worked out perfectly!

Dave
Comment » September 21, 2006 @ 8:01 am

What is the call that I’d use if I want to pull in an external post?

Tim
Comment » September 24, 2006 @ 8:19 am

This should be an official WordPress plugin. Can their team give a match? ;)

Robert
Comment » September 28, 2006 @ 5:06 am

Great plug-in. Thanks!
I will suggest that if you want the sticky post to be shown only in the first page using WP2.0 style, do:
if (is_home() && !is_paged()) {
get_a_post(1);
echo “”;
the_title();
echo “”;
the_content();
}

Sam Stevens
Comment » October 6, 2006 @ 12:28 am

Great plugin! I’m using it with 2.0.2 and getting some errors in the admin area though, specifically on the Links tab, and also whenever I activate/deactivate a plugin. It would be awesome if this could be remedied!

Sam Stevens
Comment » October 13, 2006 @ 12:28 pm
marek
Comment » November 6, 2006 @ 12:08 pm

Great plugin, starting to use it with conditional tags at the top of my pages/categories. I can’t figure out the conditional tags for Jerome’s Keyword plugin, something like:
elseif(is_tag(‘mykeyword’)) {
get_a_post(‘keywordpagetext’);
the_content();
}
Ofcourse is_tag doesnt work! Probably missing something simple.
Thanks again
Marek

marek
Comment » November 6, 2006 @ 6:53 pm

ok I am dumb.
elseif('index.php?tag=mykeyword')
{ get_a_post(’keywordpagetext’);
the_content();}

works lovely.

Paul
Comment » December 22, 2006 @ 11:05 am

Looks very promising. But in my Firefox 2.0.0.1 the page looks slightly different that in IE. I’ll double-check, may be I missed something, it was late night :*)

Adam k
Comment » December 22, 2006 @ 6:58 pm

HEy was wondering if anyone else is having this problem, Using the get_a_post plugin, when I am showing a trucated post on the main page of the site I am getting the  in various place in the site. Can any one let em know what is causeing this? Using the latest version of this plugin and WP 2.0.5

Thanks

Jenn
Comment » February 12, 2007 @ 3:07 pm

Does anyone have this working in WordPress 2.1? If so, what changes did you have to make? I get this error:
Fatal error: Call to undefined function get_a_page() in /var/www/html/ltp/wp-content/themes/spi/sidebar.php on line 44
I think its because the plugin code uses $table.

Colin
Comment » February 20, 2007 @ 1:01 pm

@Jenn – it works perfectly for me in WordPress 2.1. No problems at all.

Thank you Kaf for this excellent plug-in!

santiago
Comment » February 22, 2007 @ 12:24 pm

perfect in 2.1, great plugin.
my only problem is that the (more…) link isn’t translated with a spanish language package for WP, how can i make it work??
regards.

jeremy
Comment » February 23, 2007 @ 3:31 pm

Kaf, get-a-post works great now that the (id) defaults to the last post, but what if I only want the last post of a specific category?

John
Comment » February 25, 2007 @ 4:38 pm

Ok…. i put this in home.php, just before

then all my post have the same content!!!???

John
Comment » February 25, 2007 @ 4:40 pm

(the above thing is broken!!!)

(the underscores in front of)

after this:

then all my posts display the same thing???

Mark McLaren
Comment » March 20, 2007 @ 3:17 am

Kaf,
Awesome plugin. This is something I have been trying to figure out for a long time. It will make my life much easier. It’s another step toward making WordPress the best CMS available for small and medium-sized mainstream websites, not just blogs.

I am using it on the home page of this site: http://www.park-creative.com/ so that the site owner can edit the text in the green box, which is not part of The WordPress Loop.

Ninjaboy
Comment » April 4, 2007 @ 5:22 am

I love this plugin, and have rolled it out to a number of sites with no trouble.

However, I just couldn’t work out a way for it to select random pages (yup, pages, not posts – which creates an issue with categories), so I put the page slugs into an array, and selected randomly from those, inserting a variable into the get-a-post argument.

It worked fine, but is there an easier way to do this? I see that ‘random’ is mentioned a couple of times in the comments, but there is no indication on how to actually do this!!

neospyce
Comment » April 20, 2007 @ 3:14 am

Great plugin! I am new to php but an old hand at hard-coding html. I installed with no probs. Except when I enter the parameters as per your first example, the post appears twice. I only want the introductory post to be displayed once, not again immediately underneath it. Hope that makes sense. (In other words, the title and content are fine and appears where it should, but then the original content appears directly underneath what was pulled. It’s like a double post. I am at a loss. Please Help. The syntax is correct, my parameters somehow are lacking, I think.) I reverted back to the original index.php code. I would really like to use get-a-post, but I just need a little guidance as to the parameters.

ubustu
Comment » April 20, 2007 @ 3:24 am

The greatest WordPress plugin ever created!

neospyce
Comment » April 20, 2007 @ 3:48 am

Got It! I had to create a new page with the desired text and then called up by id on page instead of id on a post. Works like a charm.

BigCheese
Comment » April 23, 2007 @ 12:46 am

Great plugin! I’ve made a little redirect to show the SINGLE page since calling get a post doesn’t seem to extend comment functionality… this way whenever someone goes to your site, the first thing they’ll be shown is your most recent post.

ID;
header( $insert ) ;
?>

check it out at http://www.fearfulcheese.com/news/

BigCheese
Comment » April 23, 2007 @ 12:47 am

oops, this comment box nixed some of my code…

ID;
header( $insert ) ;
?>

Mogeilen
Comment » May 7, 2007 @ 4:08 pm

Hi, could anyone tell me how to do posting starting with each alphabet to display separately. Here is the example :

A…..
A…..
A…..

Only posts start with the alphabet A to be display from a specific category, let say cat1. I need to insert the code in alphabetical Tab menu in my site http://www.123indianonline.com

Thanks in advance!

Jayce
Comment » May 21, 2007 @ 4:50 pm

Perfect! I needed just what you have. Now at the top of each category page is a brief blurb (along with the MORE tag) about that category. Following the blurb is the most recent post. Your plugin does exactly what I needed. Thanks.

David
Comment » May 28, 2007 @ 11:47 am

Is there a way to put wp_title – or a php variable defined as such – inside the get_a_post tag, in place of a fixed page name or slug?

I’m trying to match up a pull-quote, named foo-pullquote, for corresponding page foo, so that an author can:

A) create a new Page or Post, and then
B) create a matching new pullquote as another Page or Post, and then
C) have the pullquote page/post auto-called by generating its name (plus “-pullquote”) from the current page

So, instead of get_a_post(‘about-pullquote’), I’m trying to generate the coded equivalent of get_a_post (‘(wp_title)-pullquote’) or get_a_post(‘$variable-pullquote’).

Any ideas?

David
Comment » May 28, 2007 @ 3:01 pm

Nevermind, PHP variable works fine, I was using faulty syntax (php newbie here).

Ian Harris
Comment » June 5, 2007 @ 8:19 am

Hi David,

I’m trying to do the exact same thing as you – please could you outline how you managed to do it?

Many thanks!

Ian

John
Comment » July 15, 2007 @ 6:20 pm

I’m trying to output just the content of a page. I’m using get-a-post(26) which is the id of the page. I’m putting this into a static homepage and the only other php code I have is require(‘wp-blog-header.php’) to make use of everything. I’m not getting any errors back but its not outputting any content from the page either. I’m using WP2.2. Am I doing something wrong or do I need an updated version of somekind?

Hint
Comment » August 6, 2007 @ 3:34 pm

Hi, Great plugin. I’m having a problem with the next page previous page option for posts in my middle column. I have used your plugin on both the left and right sidebars to show a content page that links to other pages inside the middle column. Everything works fine until I break a post with the {!–nextpage–} option. When you go to the next page, all the content goes to the side bars in addition to the center content. I know that this is because of the {?php the_content(); ?} coding that goes into the sidebar.php but is there a way to make it stay, a code that can be added as an alternate so that the content from posts won’t go in the content for my get a postie’s? Thanks

gymgangsta
Comment » August 25, 2007 @ 3:34 pm

This works great with excerpt reloaded.

Dave
Comment » September 5, 2007 @ 12:09 pm

Is there any way to make the Title a link? Great plugin, by the way!

Dave
Comment » September 5, 2007 @ 12:14 pm

Never mind, I just figured it out. Just wrap the permalink tag around it.

Benoît G.
Comment » September 28, 2007 @ 1:21 pm

I made some change to your function (http://pastebin.ca/718721), adding optionals parameters in the function ($sort=’DESC’,$status=’publish’) that you can specify.

For example, if you want to have an intro post for a category; change its date so it’s the older and put its status to DRAFT; and modify the template for the choosen category !

alias
Comment » October 17, 2007 @ 2:22 pm

how to get the read more link to appear ?

miss li
Comment » October 27, 2007 @ 4:03 am

how to get the read more link to appear ?

Kaf
Comment » October 27, 2007 @ 5:50 am

The ‘read more’ link should be appearing if:

  1. You are using the <!--more--> quicktag in your posts.
  2. You are using the_content() to display your posts.
    Josh
    Comment » January 5, 2008 @ 12:47 pm

    How can I pass a variable to get_a_post(insert variable here)

    pro01
    Comment » January 21, 2008 @ 5:57 am

    Yep, good plugin, except for the unpleasant bug I encountered – if the post is paged, each page besides the first will display the content of the current post instead of the content of the post you want to fetch. Ideas how to fix this anyone?

    Wizzoh
    Comment » January 27, 2008 @ 9:06 pm

    Kaf… Do you avoid posts about “specific category” on purpose ? Everybody here wants to display the latest post from a specific category!

    PLG
    Comment » February 4, 2008 @ 11:05 am

    I want to display latest post from a specific category. I know a hack has been posted here… but it do not work with recent version of WordPress… Can someone help me to do it ?

    mrbloggr
    Comment » June 13, 2008 @ 1:50 pm

    I’m using this exact example as above and I’m not getting the post id I specific but instead get the last post.

    <?php get_a_post(123); ?>

        <h3><?php the_title(); ?></h3>
        <?php the_content(); ?>

    Help?

    jhz
    Comment » June 27, 2008 @ 2:49 pm

    mrblogger,

    I’ll bet you need to change the post ID example (123) to a post ID that exists within your blog.

    jhz
    Comment » June 27, 2008 @ 3:34 pm

    I love this plugin–thanks! I’m not great at PHP–has anyone wrapped an if statement around this so it won’t display if the post doesn’t exist? I’m using it for an alert with a background set on the div, so the background still shows if the post is unpublished.

    My work-around was to embed the styling in the post but I’d rather not…TIA…

    jhz
    Comment » June 29, 2008 @ 12:38 pm

    Correction and comment: I need to use an if statement to display a post ID (with special DIV) and but do nothing (NOT display DIV) if the publish status is unpublished. It seems simple but I just can’t get it. I’d be willing to donate if I could use get_a_post in this way…again, TIA.

    Thomas
    Comment » July 14, 2008 @ 3:48 am

    Hello…

    your skript is wonderful, but i have one question:

    if i’ve got a picture in my post, why isn’t it displayed.

    is there a way to display the picture??

    please help me S.O.S

    with regards

    michael
    Comment » August 11, 2008 @ 1:36 am

    This doesn’t seem to want to work in my WP 2.6 installation.

    I installed it, activated it, and I have used the code: in an include file which is included in my ‘page.php’ template theme, but still no success.

    What am I doing wrong?

    I just want to display the post on my page.

    michael
    Comment » August 11, 2008 @ 2:54 am

    Is there a way I can state that it has to be the most recent post from a specific category?
    Like cat=1&order-by=date , something like this?

    andrea
    Comment » September 8, 2008 @ 6:59 pm

    I too haven’t been able to get a post by specific category….

    Daniel Smith
    Comment » September 18, 2008 @ 5:31 am

    Hi, I am using this to place a section at the top of my homepage with site descriptions (usual welcome things) etc. Unfortunately, I am also using the plugin wp-limit-posts-automatically (http://wordpress.org/extend/plugins/wp-limit-posts-automatically/) which I have set to limit the size of all posts to 100 letters with a ‘read more’ link.

    Is there some way to make this section added with Get-a-Post be treated as something other than a post, so it remains unaffected?

    Thank you for your time.

    Michael
    Comment » September 22, 2008 @ 10:30 am

    HI!

    If I wanted to get a random post from category 11 and show ONE post.

    How would i do this?

    Thank you!

    Max
    Comment » October 1, 2008 @ 9:54 am

    Thanks this is a great plugin! however can this plugin be made into a widget?

    RomeLoft
    Comment » October 7, 2008 @ 1:42 pm

    Thank you very much for this useful plugin, we’d love to see a customizable widget version as well!

    web designer
    Comment » November 7, 2008 @ 2:17 am

    I used this to get the latest post from a category and it worked very fine without using the plugin:

    http://codex.wordpress.org/Template_Tags/get_posts

    Am not sure if this will work for pages put it turn on very well for posts

    Annoyed
    Comment » November 23, 2008 @ 12:13 am

    I can’t get this to work at all. Where do you put it? I’ve got a static home page that I designated in my control panel. Then, I also designated in the control panel that “news-tips” should be the main posts page. I want an introductory paragraph at the top of that page before the posts start. Spent over an hour trying to figure out your plug in with NOTHING happening at all. Help.

    Dennis Wurster
    Comment » December 18, 2008 @ 2:18 pm

    We love get_a_post! But alas, it doesn’t seem to be working with WP 2.7. :-( Any chance you’ll consider freshening it?

    We get the following error:

    Fatal error: Call to undefined function get_a_post() in /home/web/users/2029.big6/sites/big6/public_html/go/wp-content/themes/cordobo_green_park_09/index.php on line 17

    TC
    Comment » January 12, 2009 @ 5:31 am

    This is cool! I have download it and works great. But i wondering is there anywhere we control the $id in get_a_post()? Perhaps control the $id with the custom field value? so that we can easily apply different post at one.

    Karl
    Comment » February 26, 2009 @ 12:14 pm

    Seems to work fine for me in 2.7.1 – at first I got “headers already sent out” when adding content for a post in the admin, but I removed the blank space at the end of the PHP file and that seemed to do the trick.. fingers crossed.

    charles
    Comment » March 1, 2009 @ 5:40 pm

    Hello…
    your skript is wonderful, but i have one question:
    if i’ve got a picture in my post, why isn’t it displayed.
    is there a way to display the picture??
    please help me S.O.S
    with regards

    I don’t see the anwser for this can you help me

    booobooo
    Comment » March 24, 2009 @ 10:19 am

    Here’s a question: I’ve used this plug-in but I don’t understand why you don’t have to “close” it. You can say:

    And then just move on to other business. Why is this? Why doesn’t it need to close?

    Matt
    Comment » April 11, 2009 @ 5:39 pm

    I was curious if there was a way to get “get_a_post” to works with tags

    For example retrieve a post from your archives with a certain specific tag.

    If someone can help me with this and post it here i would be very appreciative, I have tried with this for some hrs now and have been unable to figure it out.
    I can get it to work with a specific page etc but not with certain tags.

    Thanks in advance

    Matt

    Skexhi
    Comment » April 14, 2009 @ 6:20 pm

    I was wondering if anybody knows how to GET the posts from a specific user with this function??

    booooboooooooo
    Comment » May 9, 2009 @ 9:45 am

    Is there a way to have get-a-post retrieve a category page (i.e. archive.php)?

    boooooboooooooo
    Comment » May 15, 2009 @ 6:37 am

    My question about “closing” the getapost feature actually ended up having a real consequence. On this site: http://tinyurl.com/one7ko I used getapost to create the links for the two little boxes on the lower right (the map and SCOTUS) so that they’d still work when the site moved directories (which it did). But when it came time for sociable to create the links to facebook etc in the footer, the open getapost was confusing it and all the links were acting as if this was the SCOTUS page and not the home page. I had to throw in a dummy getapost refering back to the home page to trick them into referring back to the correct page. Just thought I’d point that out.

    Derek
    Comment » May 20, 2009 @ 11:36 pm

    Awesome. Did exactly what I needed. Forum problem solved: http://wordpress.org/support/topic/269313?replies=8#post-1079524

    Mike Wolstat
    Comment » June 4, 2009 @ 5:13 pm

    Thanks for this plugin.

    Is there a simple way to find out if the get_a_post() function got a post? I want to use the same template for many blogs, but if get_a_post(‘sidebar-blurb’) doesn’t find a post, I want to be able to hide the containing DIVs and H2 tags to keep the page layout clean.

    Mike Wolstat
    Comment » June 4, 2009 @ 6:44 pm

    I hacked a solution. I added this to the very end of your plugin function:

    if(count($post) == 1)
    return TRUE;
    else
    return FALSE;

    which allows me to code like this in my sidebar template:

    if (get_a_post(‘sidebar-blurb’)) {
    the_title, HTML, the_content, whatever…
    }

    that way, if there’s no page/post with ‘sidebar-blurb’ for a slug, I don’t have unused markup floating around in my sidebar. hope this helps someone.

    Dirk
    Comment » August 20, 2009 @ 5:07 pm

    Brilliant plugin. I there a way to show a post only if post_content LIKE ‘%anything%’ ?

    John
    Comment » January 13, 2010 @ 10:46 pm

    Is it possible this can be used for pulling related-post headers ?

    Example: A newspaper blog, front page news with related post attached to that particular post, I’m quite sure this plugin would do that but unsure how or if it 100% can ?

    The website in question is http://www.snakepass.com.au here you can see on the front page I have added these plugins and they work fine apart from I have pulled out the word count, I just want the HEADERS/TITLES on the four post with thumbnails, needs to be in the loop too so it automatically pulls 1 or 2 related-links to that particular post, keeps it nice and neat.

    Cheers

    Federico
    Comment » May 23, 2010 @ 7:41 pm

    To display posts from a specific category or autor try these simple querys:

    BY CATEGORY

    ?php query_posts(category_name=news&showposts=3'); ?>
    ?php while (have_posts()) : the_post(); ?>
    ?php the_title(); ?>
    ?php the_excerpt(); ?>
    a href="">More
    ?php endwhile;?>

    BY AUTHOR

    ?php query_posts(author_name=Jake&showposts=3'); ?>
    ?php while (have_posts()) : the_post(); ?>
    ?php the_title(); ?>
    ?php the_excerpt(); ?>
    a href="">More
    ?php endwhile;?>

    you can remove the ‘_name’ part if you want to use a category or author numeric ID

    I’m not able to post code so I’ve removed the first char. it’s a &lt ofc.

    bepresents
    Comment » June 4, 2010 @ 2:53 pm

    Hey guys can anyone answer this question?

    I’m migrating a site to WordPress that has very extensive SEO work on it so we want to keep all the old pages. I tried making a duplicate of WordPress’s index.php page, for example : page2.php

    If page2.php is a duplicate of WordPress’s index.php what code can I put into it, or the theme files, that will make page2.php ONLY load WordPress page id=123?

    Thanks in advance!

    Chris
    Comment » July 17, 2010 @ 9:34 am

    Great plugin! Thankyou this is exactly what I needed, perfect for sites I’m building using WordPress as a CMS.

    One quick question / suggestion though, I don’t know if this is possible but I would like to be able to get a random post from a specific category – this would be a great feature for a page related dynamic sidebar.

    If not then I’m not too bad with php so I might try to customise it. Hopefully this will be easily done buy incorporating some extra functionality using something like query_posts('category_name=my-category&showposts=6');. I’m still getting to grips with oophp though so I’ll see how it goes.

    Thanks again

    Chris
    Comment » July 17, 2010 @ 4:27 pm

    Hey Kaf,

    I decided to go ahead and try to make the functionality for displaying multiple random posts from a specific category. In my research I found this plugin called “Random Posts Widget” which could select a specified number of random posts – but it didn’t support categories! So I decided to see if I could combine it’s functionality with your plugin. I started off editing the two plugin’s code together but this was proving tricky, so after a while I found an easier way…

    I expanded the scope of the other plugin to include categories (passed as either an ID or a slug style category name), and I’ve made it so that it returns an array of post ID’s which can then be looped through using your plugin to fetch and prepare the actual post data. So in effect I’ve made a plugin to your plugin (although this may not be efficient in terms of DB usage?!)

    Since I haven’t developed or published a wordpress plugin before but I though I should notify both you and the other plugin’s author to see what you want to do. If the functionality will be useful to you or other people, and assuming you’re both happy to then I could make the plugin available. Contact me with the email provided if you want a copy of the source code, you might be able to optimise it or implement it better than I have…

    Thanks

    Fred
    Comment » August 25, 2010 @ 6:51 pm

    Hi kaf,

    Thanks very much for this! I’m using Mike Challis’ famous ‘Fast Secure Contact Form’ in a modal lightbox but couldn’t get it to work with the normal as it grabbed the content from the database and didn’t format it as the content would have been in a page. This however is perfect and has saved me a lot of time and hassle. Thanks very much!

    marek
    Comment » September 25, 2010 @ 3:08 pm

    How long term is this plugin? It does work on latest WP. I love it and use it everywhere – and I can’t figure out why it isn’t more popular as it helps me enormously! Is there another plugin similar to this? I can’t find one on the wordpress site!
    Thanks
    M

    Big Fan
    Comment » December 4, 2010 @ 5:17 pm

    Thank you so much for creating this plugin. This is the BEST way to use WordPress, in my opinion. You can completely avoid the need for running the loop and just place content wherever you want. Absolutely perfect for making a site that a client can edit but not screw up!

    Jon
    Comment » February 8, 2011 @ 2:56 am

    Exactly what I needed too after searching high and low for the best way to implement something like this. Thanks!

    Peter
    Comment » October 5, 2011 @ 4:26 am

    Hi this is a brilliant plugin and I am using it in a site I am developing for a client. One issue I am having is getting the structure of the ‘sticky post’ ID parameter to work. I have this:

    read more’, 15, 15 ); ?>

    But when I view the page in the browser I just get a blank page.

    Am I setting the sticky parameter correctly?

    Thanks

    Peter

    Peter
    Comment » October 5, 2011 @ 4:28 am

    Sorry it didn’t display properly:

    read more’, 15, 15 ); ?>

    peter
    Comment » October 5, 2011 @ 4:29 am

    One more time!

     

    * Required field (e-mail is not published). Breaks and paragraphs are automatic. HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>