Hi there,
I'm trying to set up 2 boxes on my home page (index.php). The first box should show one post (title and contents) from the category "newsgrabs" , the second box should show titles only of the 5 most recent posts NOT in the category "newsgrabs". I'm trying to do this by resetting thematic_indexloop, then replacing with my custom function in my child theme's functions.php.
The custom function calls get_posts() twice, once for each box.
The problem I'm having is that the output seems to get mixed up between the 2 boxes. The first box shows the post contents from the correct post, but the title and permalink are wrong. The second box shows the same title and permalink 5 times.
Here is my code:
// Remove default index loop
function remove_thematic_indexloop() {
remove_action('thematic_indexloop', 'thematic_index_loop');
}
add_action('init','remove_thematic_indexloop');
function agribusiness_newsgrab() {
echo "<div id='newsgrab'>";
$posts_news = get_posts( "category=23&numberposts=1" );
if( $posts_news ) {
foreach( $posts_news as $post_n ) {
setup_postdata( $post_n );
echo '<h2><a href="';
the_permalink();
echo '" title="Permanent Link to ';
the_title();
echo '">' ;
the_title();
echo '</a></h2>';
the_content("Continue reading '" . the_title('', '', false) . "'");
}
}
echo "</div>";
echo "<div id='recentlist'>";
$posts_r = get_posts( "category=-23&numberposts=5" );
if( $posts_r ) {
foreach( $posts_r as $post_r ) {
setup_postdata( $post_r );
echo '<h2><a href="';
the_permalink();
echo '" title="Permanent Link to ';
the_title();
echo '">' ;
the_title();
echo '</a></h2>';
//the_content("Continue reading '" . the_title('', '', false) . "'");
}
}
echo "</div>";
echo "39";
}
add_action ('thematic_indexloop','agribusiness_newsgrab');
You can see the output at http://agribusiness-australia.com.au/wp2009/
I read the info at http://codex.wordpress.org/The_Loop#Multiple_Loops , and tried using the methods listed there to overcome the problem, but no dice.
Also tried the technique described at http://perishablepress.com/press/2008/09/01/multiple-loops-and-multiple-columns-with-wordpress/ . It also seemed scramble the post output.
I tried disabling all plugins. No dice.
I'm sorry if this is not directly a Thematic issue. It could be. I just dont know...
Does anyone have any clues what is happening here? I'm going crazy over this...
Thanks in advance,
Phil