ThemeShaper Forums » Thematic

[closed]

index loop: latest post, exceprt post

(19 posts)
  • Started 3 years ago by greenandi
  • Latest reply from helgatheviking
  • This topic is resolved
  1. hi,

    i wanted to show 2 latest post and then follow older posts as an exceprt.

    this already give me 2 columns exceprt.
    i got this from http://hardiannazief.com/12/create-custom-posts-layout-in-home-page-thematic-child-theme/comment-page-1/#comment-4054


    <?php
    function remove_index_loop() {
    remove_action('thematic_indexloop', 'thematic_index_loop');
    }
    add_action('init', 'remove_index_loop');

    function snippet_index_loop() {
    global $post;
    /* Count the number of posts so we can insert a widgetized area */ $count = 1;
    while ( have_posts() ) : the_post() ?>
    <?php $counter++; ?>
    <div class="column <?php if ($counter == 1) { echo 'one'; } else { echo 'two'; $counter = 0; } ?>">
    <div class="clear-fix">
    <div id="post-<?php the_ID() ?>" class="<?php thematic_post_class() ?>">
    <?php thematic_postheader(); ?>
    <div class="entry-content">
    <?php the_excerpt(); ?>
    <?php wp_link_pages('before=<div class="page-link">' .__('Pages:', 'thematic') . '&after=</div>') ?>
    </div>
    <?php thematic_postfooter(); ?>
    </div><!-- .post -->
    </div><!-- .clear-fix -->
    </div><!-- .column -->

    <?php comments_template();
    if ($count==$thm_insert_position) { get_sidebar('index-insert');}

    $count = $count + 1;
    endwhile;
    }
    add_action('thematic_indexloop', 'snippet_index_loop');

    ?>

    thanks,appreciate with the help. i'm not good with php.

    Posted 3 years ago #
  2. here is a page template that i had made to build on that 2 column layout. (to use: create a blank page in WP, call it blog, save it. this page should now behave as your blog index) basically i had the latest post in a featured box, then 3 more post excerpts then the excerpts start going into 2 columns.

    i modified it a little so that 2 full posts would show before switching to excerpts like you wanted, but didn't modify anything else. hope it gives you some ideas...

    <?php
    /*
    Template Name: Magazine Style Blog
    
    2 column layout inspired by:
    http://hardiannazief.com/12/create-custom-posts-layout-in-home-page-thematic-child-theme/
    */
    ?>
    
    <?php
    
        // calling the header.php
        get_header();
    ?>
    </div><!--end first main-->
    <?php
        // action hook for placing content above #container
        thematic_abovecontainer();
    
    ?>
    
    <?php
    
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("paged=$paged");
    ?>
    
    	 <?php $count++; $clear=''; ?>  
    
    	<?php while ( have_posts() ) : the_post() ?>
    
    	<?php if ($count==1 AND !is_paged()){ ?>
    
    	<div id="feature" >
    		<div id="feature-container" class="clearfix">
    
    			 <?php if ( function_exists( 'p75GetVideo' ) ) {
    						if(p75HasVideo($post->ID)){
    						echo '<div class="thumb">'.p75GetVideo($post->ID,460,277).'</div>';
    						} } else {
    						echo catch_that_image("277","460");
    				} ?>
    
    				<div id="post-<?php the_ID() ?>" class="<?php thematic_post_class() ?>">
    
    				<div class="user-comments">
    				<?php
    			   // Display comments link and edit link
    				if (comments_open()) {
    						$postcommentnumber = get_comments_number();
    						$postcomments = ' <span class="comments-link"><a href="' . get_permalink() . '#comments" title="' . __('Comment on ', 'thematic') . the_title_attribute('echo=0') . '">';
    						$postcomments .= get_comments_number() . '</a></span>';
    				} else {
    					$postcomments = ' <span class="comments-link">' . __('Closed', 'thematic') .'</span>';
    				}
    				echo $postcomments;
    				?>
    				</div>
    
    				<?php thematic_postheader(); ?>
    				<div class="entry-content">
    <?php 	the_content(''.__('Read More <span class="meta-nav">&raquo;</span>', 'thematic').'');
    			//the_excerpt();
    ?>
    			<p><a href="<?php the_permalink(); ?>" class="more-link" title="Read More"><?php echo  __('Read More <span class="meta-nav">&raquo;</span>', 'thematic'); ?> </a></p>
    
    				<?php wp_link_pages('before=<div class="page-link">' .__('Pages:', 'thematic') . '&after=</div>') ?>
    				</div>
    				<?php thematic_postfooter(); ?>
    
    				<div class="clear_hentry"></div>
    				</div><!-- .post -->
    
    <?php comments_template() ?>
    
    		</div><!-- #feature-container -->
    	</div><!-- #feature -->
    
    	<div id="main2">
    
    		<div id="container">
    		<div id="content">
    
    			<?php 
    
                // create the navigation above the content
                thematic_navigation_above();
    
                // calling the widget area 'index-top'
                get_sidebar('index-top');
    
                // action hook for placing content above the index loop
                thematic_above_indexloop();
    
    	 } else { // end if count=1 and is not paged aka Feature Section
    
    		if ($count==1){ //puts container and content opening divs on paged pages
    
    		    // create the navigation above the content
                thematic_navigation_above();
    
                // calling the widget area 'index-top'
                get_sidebar('index-top');
    
                // action hook for placing content above the index loop
                thematic_above_indexloop();
    			?>
    
    		<div id="container">
    		<div id="content">
    		<?php } ?>
    
    				<div class="column <?php if ($count <= 4) { echo 'none'; } elseif ($count >=5 AND ($count&1)) { echo 'one'; } elseif ($count>=4 AND !($count&1)) { echo 'two'; } else { echo 'six'; $counter = 4;} ?>">
    
    				<div id="post-<?php the_ID() ?>" class="<?php thematic_post_class() ?>">
    
    				<div class="user-comments">
    				<?php
    			   // Display comments link and edit link
    				if (comments_open()) {
    						$postcommentnumber = get_comments_number();
    						$postcomments = ' <span class="comments-link"><a href="' . get_permalink() . '#comments" title="' . __('Comment on ', 'thematic') . the_title_attribute('echo=0') . '">';
    						$postcomments .= get_comments_number() . '</a></span>';
    				} else {
    					$postcomments = ' <span class="comments-link">' . __('Closed', 'thematic') .'</span>';
    				}
    				echo $postcomments;
    				?>
    				</div>
    
    				<?php thematic_postheader(); ?>
    
    				<?php if(catch_that_image()) {
    				//echo '<div class="thumb"><a href="' .get_permalink(). '" title="' .get_the_title(). '"><img src="' .get_stylesheet_directory_uri(). '/scripts/timthumb.php?src=' .urlencode(catch_that_image()). '&amp;h=100&amp;w=200&amp;zc=1&amp;q=90"></a></div>';
    				echo catch_that_image("150","200");
    				} ?>				
    
    				<div class="entry-content">
    
    <?php 	//the_content(''.__('Read More <span class="meta-nav">&raquo;</span>', 'thematic').'');
    			the_excerpt();
    ?>
    			<p><a href="<?php the_permalink(); ?>" class="more-link" title="Read More"><?php echo  __('Read More <span class="meta-nav">&raquo;</span>', 'thematic'); ?> </a></p>
    
    				<?php wp_link_pages('before=<div class="page-link">' .__('Pages:', 'thematic') . '&after=</div>') ?>
    				</div>
    				<?php thematic_postfooter(); ?>
    
    				<div class="clear_hentry"></div>
    				</div><!-- .post -->
    				</div><!-- .column-->
    
    <?php //comments_template() ?>
    
    <?php } //end else
    ?>
    
    <?php if ($count==$thm_insert_position) { ?><?php get_sidebar('index-insert') ?><?php } ?>
    <?php $count = $count + 1; ?>
    
    	<?php endwhile; ?>
    
    			<?php
    
                // action hook for placing content below the index loop
                thematic_below_indexloop();
    
                // calling the widget area 'index-bottom'
                get_sidebar('index-bottom');
    
                // create the navigation below the content
                thematic_navigation_below();
    
                ?>
    
    		</div><!-- #content -->
    	</div><!-- #container -->
    
    <?php 
    
        // action hook for placing content below #container
        thematic_belowcontainer();
    
        // calling the standard sidebar
        thematic_sidebar();
    
        // calling footer.php
        get_footer();
    
    ?>
    Posted 3 years ago #
  3. wow thanks much!, it solved.

    Posted 3 years ago #
  4. mrmikeman
    Member

    Helga, how could i do this just for a specified category page, i want to do a two column layout but just one a category page, i understand i need to do a conditional tag and iv tried but im not putting it in right.

    i dont want to over ride the index loop or anything, i just want to style my category in columns like this code above does

    thanks!

    Posted 2 years ago #
  5. use above and call it category-{slug}.php
    see the codex on template hierarchy:

    http://codex.wordpress.org/Template_Hierarchy

    Posted 2 years ago #
  6. mrmikeman
    Member

    ok, so i did just that and now when i visit my category page i get

    Fatal error: Call to undefined function catch_that_image() in /home/ocixx/public_html/canvas/wp-content/themes/child2/category-gallery.php on line 40

    my header still loads on the page with this error.

    Posted 2 years ago #
  7. mrmikeman
    Member

    re reading what you had instructed.. creating a page called blog.. i didnt do that, but im confused... what im trying to do is create a 3 column layout for a category page "gallery" being the category.. with the code from the link you provided i was able to do that, but it did it for all categories, including the home page. .

    Posted 2 years ago #
  8. well catch_that_image() was a function i was using back in the day, and I had it defined in my functions.php. you would not have it in yours hence you'd get an undefined function error. remove the reference to this function and it should be ok.

    the original instructions call for making a page template. you could do it this way (and adjust the query) or i still think it is best to create the category template... and in which case i think you actually need to remove the query_posts() call.

    Posted 2 years ago #
  9. mrmikeman
    Member

    there are several lines in there with catch_that_image, i assume i cant just delete from |catch to image| on each one without breaking something and i wouldnt know from where to where would i remove with out removing something im not supposed to.

    do you know of any updated tutorials?

    i appreciate your help kathy

    Posted 2 years ago #
  10. no, but you could update it by removing all the image references and replacing them with the_post_thumbnail() built-in function.

    Posted 2 years ago #
  11. mrmikeman
    Member

    the pictures come out huge, im seeing the timthumb script i take it i need to install that in the child theme folder?

    Posted 2 years ago #
  12. no you don't need to use timthumb either if you don't want to. you can just use the_post_thumbnail('thumbnail') or the_post_thumbnail('medium') to control the size of the image.

    see the codex entry on the_post_thumbnail
    http://codex.wordpress.org/Function_Reference/the_post_thumbnail

    my code above was only for ideas and was never meant to be a cut and paste solution. maybe you can post yours when you get it sorted out.

    Posted 2 years ago #
  13. mrmikeman
    Member

    ok i ended up going a slightly different rout, and like usual didnt realize the whole time what i was doing was actually targeting all categories and not just one. .

    in my child theme folder, aside from css files, i have

    loop-thumbnail.php

    <?php
    global $post;
    $count = 1;
    while ( have_posts() ) : the_post();
    if(function_exists('p75GetVideo')){
    	if(p75GetVideo($post->ID)){
    		$vidclass = 'video';
    	} else {
    		$vidclass = '';
    	}
    }
    
    ?>
    		<div id="post-<?php the_ID() ?>" <?php echo post_class($vidclass); ?>>
    			<div class="entry-content">
    			<?php childtheme_post_header() ?>
            	<a href="<?php echo the_permalink() ?>">
            	<div class="post-title"><?php echo the_title(); ?></div>
            	<?php 
    
    			$thumbnail = get_post_meta($post->ID, 'thumbnail', true);
    
    			if( $thumbnail ):
    				echo '<img class="attachment-thumbnail" src="' .get_post_meta($post->ID, 'thumbnail', true) . '" width="125" height="125" alt="' . get_the_title() .'" /></a>';
            	elseif( has_post_thumbnail() ):
            		the_post_thumbnail('medium');
            	else:
    				echo '<img class="attachment-thumbnail" src="' . get_bloginfo('stylesheet_directory') . '/images/thumbnail-default.jpg" width="125" height="125" alt="' . get_the_title() .'" />';
            	endif;
            	?>
            	</a>
    		  </div>
    		</div><!-- .post -->
    
    <?php
    
    	if ($count==$thm_insert_position)
    		get_sidebar('index-insert');
    
    	$count = $count + 1;
    endwhile;
    
    ?>

    functions.php

    <?php
    // add custom style sheet for the gallery category page
    function childtheme_css() {
    if (is_category('gallery')) {?>
    <link rel="stylesheet" type="text/css" href="<?php echo bloginfo('stylesheet_directory') ?>/cat-gallery.css" /> <?php }
    }
    add_action('wp_head', 'childtheme_css');
    
    // add image sizes, give that size a name and define its measurements
    add_image_size( 'medismall', 228, 160 ); 
    
    // remove sidebar on category-page "gallery"
    function remove_sidebar() {
      if(is_category('gallery')){
        return FALSE;
      } else {
        return TRUE;
      }
    }
    
    add_filter('thematic_sidebar', 'remove_sidebar');
    
    // add custom post header
    function childtheme_post_header(){
    
      global $up_options;
    
      $gall_newlength = $up_options->new_length;
    
    	if($gall_newlength){
    		$time = $gall_newlength;
    	} else {
    		$time = 3;
    	}
    
    	if ( (time()-get_the_time('U')) <= ($time*86400) ):
    		echo '<div class="new"></div>';
    	endif;
    }
    
    // remove all loops and replace them with our thumbnail loop
    
    function remove_loops() {
    
    	remove_action('thematic_categoryloop', 'thematic_category_loop');
    }
    
    add_action('init', 'remove_loops');
    
    // add our thumbnail loop instead
    function thumbnail_loop() {
    
    	global $post;
    	get_template_part( 'loop', 'thumbnail' );
    
    }
    
    add_action('thematic_categoryloop', 'thumbnail_loop');
    ?>

    everything looks pretty, in the gallery category

    is there some way thats not all super crazy hard to define what category pages look user this setup?

    i was like.. oh snaps! i did it.. lol but not unless i want all categories to look like that, which i dont. :(

    Posted 2 years ago #
  14. you are using is_category() logic to add the stylesheet. why not try that for adding and removing the category loops?

    OR, you could duplicate category.php and rename it to category-{slug}.php like i mentioned above. then you could replace thematic_categoryloop with your custom loop.

    Posted 2 years ago #
  15. mrmikeman
    Member

    okay im seeing what i could do but im getting a syntax error on the else tag unexpected t else error ,but im pretty sure i need it

    // remove all loops and replace them with our thumbnail loop
    function remove_loops() {
    	if ( is_category('gallery') ) {
    	remove_action('thematic_categoryloop', 'thematic_category_loop');
    	}
    }
    
    add_action('init', 'remove_loops');
    
    // add our thumbnail loop instead
    function thumbnail_loop() {
    } else {
    	global $post;
    	get_template_part( 'loop', 'thumbnail' );
    
    add_action('thematic_categoryloop', 'thumbnail_loop');
    
    }
    Posted 2 years ago #
  16. parse errors mean you are missing something like a ; } )

    // add our thumbnail loop instead
    function thumbnail_loop() {
    } else {
    	global $post;
    	get_template_part( 'loop', 'thumbnail' );
    } //you forgot to close this ELSE statement
    add_action('thematic_categoryloop', 'thumbnail_loop');
    
    }
    Posted 2 years ago #
  17. mrmikeman
    Member

    is an unexpected else tag a parse error? cause i figured i was missing something but im trying to add them anywhere i could(accept the right spot) and it wont budge lol

    i closed it how you showed me but still telling me theres an error on line 92, being the line with }else{

    Posted 2 years ago #
  18. mrmikeman
    Member

    im getting somewhere....

    http://ocixx.com/canvas/category/gallery/
    http://ocixx.com/canvas/category/uncategorized/

    as you see, the gallery cat is styled how i want it, and uncat.. is how it is by default.

    but im pretty sure the home page had thumbs on it before.. so i need to figure out whats interfering with that.. :-D

    Posted 2 years ago #
  19. idk if it is exactly a parse error, but it means that it is usually missing something that should be there BEFORE the else statement. i looked again and definitely missed something.. you can't have an ELSE without an IF, and you don't need the else part anyway.

    // add our thumbnail loop instead
    function thumbnail_loop() {
        if ( is_category('gallery') ) {
    	global $post;
    	get_template_part( 'loop', 'thumbnail' );
    }
    add_action('thematic_categoryloop', 'thumbnail_loop');
    
    }

    though i'm curious if you could combine the 2 functions:

    // remove all loops and replace them with our thumbnail loop
    function mod_loops() {
       if ( is_category('gallery') ) {
    	remove_action('thematic_categoryloop', 'thematic_category_loop');
            add_action('thematic_categoryloop', 'thumbnail_loop');
       }
    }
    
    add_action('init', 'mod_loops');
    
    // add our thumbnail loop instead
    function thumbnail_loop() {
    	global $post;
    	get_template_part( 'loop', 'thumbnail' );
    }
    Posted 2 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.