ThemeShaper Forums » Thematic

[closed]

Custom display of posts

(4 posts)
  • Started 14 years ago by kbkisan
  • Latest reply from kbkisan
  • This topic is resolved
  1. kbkisan
    Member

    Hi there.

    I have a question regarding custom display of posts in the Thematic template.

    Previously in this forum I requested help about how to remove a category from the blog and display it in another page.

    And this is the code I use in the function.php to achieve this.

    // Remove category 3 from the blog
    
    function exclude_category($query) {
    	if ( $query->is_feed || $query->is_home ) {
    		$query->set('cat', '-3');
    	}
    return $query;
    }
    add_filter('pre_get_posts', 'exclude_category');
    
    function childtheme_previous_post_link_args($args) {
    		global $wp_query;
    		$category = get_the_category();
    		echo $category->cat_ID;
    		if (in_category('3')) {
    	$args = array ('format'              => '%link',
    	 'link'                => '<span class="meta-nav">&laquo;</span> %title',
    	 'in_same_cat'         => TRUE,
    	 'excluded_categories' => '');
    			}
    		else {
    	$args = array ('format'              => '%link',
    	 'link'                => '<span class="meta-nav">&laquo;</span> %title',
    	 'in_same_cat'         => FALSE,
    	 'excluded_categories' => '3');
    		}
    		return $args;
    }
    add_filter('thematic_previous_post_link_args', 'childtheme_previous_post_link_args');
    
    function childtheme_next_post_link_args($args) {
    		global $wp_query;
    		$category = get_the_category();
    		echo $category->cat_ID;
    		if (in_category('3')) {
    $args = array ('format'              => '%link',
    		'link'                => '%title <span class="meta-nav">&raquo;</span>',
    		'in_same_cat'         => TRUE,
    		'excluded_categories' => '');
    			}
    		else {
    $args = array ('format'              => '%link',
    		'link'                => '%title <span class="meta-nav">&raquo;</span>',
    		'in_same_cat'         => FALSE,
    		'excluded_categories' => '3');
    		}
    		return $args;
    }
    add_filter('thematic_next_post_link_args', 'childtheme_next_post_link_args');
    
    // Code to display category 3 with in my custom page
    
    function child_theme_custom_query() {
    
        	if (is_page('3')) { // change '48' to the id # of your page
    
    	$limit = get_option('posts_per_page');
        	$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
            //change '4' to you category id # and change the value of $limit to the # of posts you want displayed per page
        	query_posts('cat=3' . '&showposts=' . $limit=4 . '&paged=' . $paged );
    
        	$wp_query->is_archive = true; $wp_query->is_home = false;
        	}
    
    }
    
    add_action('thematic_above_indexloop', 'child_theme_custom_query');

    What I need now is basically to have 1 page with the blog (category 1) without category 3, a page with just category 3 (both already working) and on top of that now I need a page that displays 1 post from the category 3 page and 4 posts from the blog (category 1), and I have tried a lot of stuff without success and I was hoping someone could help me out

    Posted 14 years ago #
  2. kbkisan
    Member

    No one up for the task :Þ . I've been looking all over for info, and am reading about the Thematic hooks and filters but I'm not able to figure this one out. Any help would be greatly appreciated

    Posted 14 years ago #
  3. I wrote a response, but I read through your question again and realized I didn't quite answer it. That's a complicated query_posts call for sure.

    Posted 14 years ago #
  4. kbkisan
    Member

    Hi Devin and thanks for your reply. I managed to dig something up last night from the forums and found this code that resolves my problem for now.

    // CREATE SPECIAL HOMEPAGE WITH ENTRIES FROM CAT 3 AND CAT 1
    
    function agribusiness_newsgrab() {
    
    	if (is_page_template('home-template.php')) { // change '48' to the id # of your page
    
    	echo "<div id='expoactual'>";
    		$posts_news = get_posts( "category=3&numberposts=1" );
    		if( $posts_news ) {
            	foreach( $posts_news as $post_n ) {
    			setup_postdata( $post_n );
    				echo '<h2><a href="';
    				 echo (get_permalink($post_n->ID));
    				 echo '" title="Permanent Link to ';
    				 echo (get_the_title($post_n->ID));
    				  echo '">' ;
    				 echo (get_the_title($post_n->ID));
    				  echo '</a></h2>';
    				  //echo (get_the_content($post_n->ID));
    					the_content("Continue reading '" . the_title('', '', false) . "'");
    				}
    			}
    	echo "</div>";
    
    	echo "Darreres entrades al blog";
    
    	echo "<div id='recentblogs'>";
    		$posts_r = get_posts( "category=-3&numberposts=3" );
    		if( $posts_r ) {
            	foreach( $posts_r as $post_r ) {
    				setup_postdata( $post_r );
    				echo '<h2><a href="';
    				 echo (get_permalink($post_r->ID));
    				 echo '" title="Permanent Link to ';
    				 echo (get_the_title($post_r->ID));
    				  echo '">' ;
    				 echo (get_the_title($post_r->ID));
    				  echo '</a></h2>';
    //  				  echo (get_the_content($post_n->ID));
    
    					//the_content("Continue reading '" . the_title('', '', false) . "'");
    				}
    			}
    	echo "</div>";
    
    	}
    }
    add_action ('thematic_indexloop','agribusiness_newsgrab');
    
    // END CREATE HOMEPAGE
    Posted 14 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.