WP plugin: Get-a-Post
- plugin:
- Get-a-Post
- version:
- R1.3
- download:
- get-a-post.zip
- source:
- get-a-post.php
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:
10or'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).
'GETRANDOM' id, which retrieves (surprise!) a random published post (but as always, just one).'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.'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…
Author: Kaf Oseo
Categories: WordPress
Comments: (141) · Leave a comment · Comments RSS2
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!
{{{{{Kafkaesquí}}}}}
“Bracket my name all you want, but you’ll never box me in!”
I wonder if that’s a famous quote…
Wouw, very nice script. Love it :D Use it on my website now.. Keep it up!!
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!
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
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.It works with conventional PHP if statement?
I’ve tried with:
php if(is_page(’24′) && $splitpage ==”2″) : ?>
php get_a_post(5); ?>
php the_content(); ?>
php endif; ?>
(sorry for double comment)
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!
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?
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.)
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 10Warning: 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
Thanks, just what i have been looking for to show some author info in the sidebar. It’s simple and it works.
if id would default to the last post, this plug would be perfect for me.
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.
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
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.
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.
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.
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
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
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?
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?
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.
Not working for me on 2.0.2. Defaulting to last page created. Much sadness.
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?
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.
@rob – thx a lot for the tip. it helped me with the problem. how long did you search for this detail?!
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?
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?
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.
Anything new yet about fixing this issue????
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
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!
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.
I also had to add the parentheses to that last line on my WordPress 2.0.2 installation.
Sorry for the delay on the bug fix everybody. For your patience, I added the new ‘GETSTICKY’ id. See the April 21st update.
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?
i want to set a sticky post on the top with this plugin
what will be the code for it
thanks for help !!!
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;
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)
Is there any demo on what can this plugin do?
Sorry as I can’t really understand the description…
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?
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
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
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.
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
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?
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.
thank you for this one. it worked out perfectly!
What is the call that I’d use if I want to pull in an external post?
This should be an official WordPress plugin. Can their team give a match? ;)
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();
}
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!
Resolved! http://wordpress.org/support/topic/90461
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
ok I am dumb.
elseif('index.php?tag=mykeyword'){ get_a_post(’keywordpagetext’);
the_content();}
works lovely.
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 :*)
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
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.
@Jenn – it works perfectly for me in WordPress 2.1. No problems at all.
Thank you Kaf for this excellent plug-in!
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.
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?
Ok…. i put this in home.php, just before
then all my post have the same content!!!???
(the above thing is broken!!!)
(the underscores in front of)
after this:
then all my posts display the same thing???
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.
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!!
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.
The greatest WordPress plugin ever created!
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.
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/
oops, this comment box nixed some of my code…
ID;
header( $insert ) ;
?>
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!
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.
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?
Nevermind, PHP variable works fine, I was using faulty syntax (php newbie here).
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
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?
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
This works great with excerpt reloaded.
Is there any way to make the Title a link? Great plugin, by the way!
Never mind, I just figured it out. Just wrap the permalink tag around it.
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 !
how to get the read more link to appear ?
how to get the read more link to appear ?
The ‘read more’ link should be appearing if:
<!--more-->quicktag in your posts.the_content()to display your posts.How can I pass a variable to get_a_post(insert variable here)
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?
Kaf… Do you avoid posts about “specific category” on purpose ? Everybody here wants to display the latest post from a specific category!
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 ?
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?
mrblogger,
I’ll bet you need to change the post ID example (123) to a post ID that exists within your blog.
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…
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.
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
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.
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?
I too haven’t been able to get a post by specific category….
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.
HI!
If I wanted to get a random post from category 11 and show ONE post.
How would i do this?
Thank you!
Thanks this is a great plugin! however can this plugin be made into a widget?
Thank you very much for this useful plugin, we’d love to see a customizable widget version as well!
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
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.
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:
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.
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.
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
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?
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
I was wondering if anybody knows how to GET the posts from a specific user with this function??
Is there a way to have get-a-post retrieve a category page (i.e. archive.php)?
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.
Awesome. Did exactly what I needed. Forum problem solved: http://wordpress.org/support/topic/269313?replies=8#post-1079524
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.
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.
Brilliant plugin. I there a way to show a post only if post_content LIKE ‘%anything%’ ?
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
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 < ofc.
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!
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
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
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!
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
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!
Exactly what I needed too after searching high and low for the best way to implement something like this. Thanks!
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
Sorry it didn’t display properly:
read more’, 15, 15 ); ?>
One more time!