Homepage auto-update on Word Press
Currently, I update all the teasers on our homepage by hand: http://www.chicagonewscoop.org/
Clearly this sucks and is unnecessary, but when I redesigned our home page I lost the code that grabbed the latest post in each category (up to the tag) and generated a teaser such as you see now.
Unfortunately, my php skills are too non-existent to bring that auto-update feature back.
Is there some way to fix this state of affairs?
Leave a Reply
You must be logged in to post a comment.
2 Answers
Let me try throwing some template tags into the code from Megan's answer to adapt it to your site:
<ul><li>
<?php
global $post;
$myposts = get_posts('numberposts=1&&category=1');
foreach($myposts as $post) :
setup_postdata($post);
?>
<strong>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</strong><br />
<em>
<?php the_time('F j, Y'); ?> | <?php the_author_posts_link(); ?>
</em><br><br>
<?php the_excerpt(); ?>
<?php endforeach; ?>
</li></ul>
I think that should work. Repeat as needed. You don't need "offset" from the Codex example. Change "category=1" to the ID# found for each category in the control panel. Or use the parameter "category_name=news" instead. For more customization options see docs for permalink, time and date formatting, author posts link, excerpt -- especially the handy Related section at the bottom.
Leave a Reply
You must be logged in to post a comment.
Depending on how non-existent your PHP is, this should do it: http://codex.wordpress.org/Template_Tags/get_posts
Answer for follow-up question on removing ellipses from post excerpts:
Remove [...] string using Filters
Only in version 2.9 and higher of WordPress
By default, excerpt more string at the end is set to '[...]'. To change excerpt more string using excerpt_more filter, add the following code to functions.php file in your theme:
function new_excerpt_more($more) {
return '[.....]';
}
add_filter('excerpt_more', 'new_excerpt_more');
For versions 2.8.x and Older
function new_excerpt_more($excerpt) {
return str_replace('[...]', '...', $excerpt);
}
add_filter('wp_trim_excerpt', 'new_excerpt_more');
from: http://codex.wordpress.org/Template_Tags/the_excerpt
Leave a Reply
You must be logged in to post a comment.
Your Answer
Please login to post questions.

Ooops, didn’t see Megan already had that answer but better, below. If it doesn’t work, look at the PHP of your plugins in /wp-content/plugins/whatever. A plugin might be adding its own filter to the excerpt, so look for a line like add_filter(‘excerpt_more’, ‘something’); or add_filter(‘the_excerpt’, ‘evil_doing’); then delete or comment that line out. http://www.tizag.com/phpT/comment.php You’ll probably have to repeat this process whenever you update the guilty plugin. So if you don’t need it, lose it. My first suspect would be the ShareThis plugin.
Ooops, didn’t see Megan already had that answer but better, below. If it doesn’t work, look at the PHP of your plugins in /wp-content/plugins/whatever. A plugin might be adding its own filter to the excerpt, so look for a line like add_filter(‘excerpt_more’, ‘something’); or add_filter(‘the_excerpt’, ‘evil_doing’); then delete or comment that line out. tizag.com/phpT/comment.php You’ll probably have to repeat this process whenever you update the guilty plugin. So if you don’t need it, lose it. My first suspect would be the ShareThis plugin.
Ooops, didn’t see Megan already had that answer but better, below. If it doesn’t work, look at the PHP of your plugins in /wp-content/plugins/whatever. A plugin might be adding it’s own filter to the excerpt, so look for a line like add_filter(‘excerpt_more’, ‘something’); or add_filter(‘the_excerpt’, ‘evil_doing’); then delete or comment that line out. http://www.tizag.com/phpT/comment.php You’ll probably have to repeat this process whenever you update the guilty plugin. So if you don’t need it, lose it. My first suspect would be the ShareThis plugin.
Perhaps a plugin or a theme is throwing that in? First check your theme’s function.php file and look for new_except_more as noted in http://codex.wordpress.org/Template_Tags/the_excerpt#Remove_.5B….5D_string_using_Filters There’s probably already something there, change it to what you want to follow the excerpt.
The share button and the “read more” ellipsis: [...]
Any ideas?
Worked like a charm once I used the category_name parameter. Thanks so much!
Now I just need a way to prevent that pesky “share” button from being pulled in as well, as you get in the archives: http://www.chicagonewscoop.org/category/james-warren/
Oooh, nice. I was lazy.