ThemeShaper Forums » Thematic

[closed]

How to make category pages show the Content of the last Post?

(9 posts)
  • Started 3 years ago by benfrain.com
  • Latest reply from helgatheviking
  • This topic is not resolved

Tags:

  1. Right, my first time using the thematic framework and I'm a little in 'awe' of it at present. Can anybody give me some advice on this - feel free to explain to me like I'm a 3 year-old ;)

    I'd like to modify my category pages so that they only show the content of the latest post within the category in full.

    What's the best practice way of going about this in Thematic?

    Posted 3 years ago #
  2. at first i thought you'd want to override the category loop, but actually i think you'll be better served just adding content above the category loop. i don't have time to do it for you right now, but the basic method for adding content is

    function bacon(){
      echo "yay bacon!";
    }
    add_action('name_of_hook_to_add_to','bacon'); //bacon is name of function to be added to hook

    the proper hook in this case will be:
    thematic_above_categoryloop

    check these 2 references for a visual display of the available hooks:
    http://www.bluemandala.com/thematic/thematic-structure.html
    http://visualizing.thematic4you.com/

    the content you are looking to add (since obviously echoing out bacon isn't what you're after) will probably best be handled by

    get_post(), though think you could also use get_posts() but since you only want the latest- i'd say the former is suited.

    see the codex:
    http://codex.wordpress.org/Function_Reference/get_post
    http://codex.wordpress.org/Function_Reference/get_posts

    good luck

    Posted 3 years ago #
  3. Helga, I'm indebted to you once more. Thanks for those pointers - I'll take a good look...

    Posted 3 years ago #
  4. OK, so having done the easy bit of getting 'Bacon' on every category page ;) I'm now struggling with the post part. I've had a good look at the codex docs but as I'm primarily a front-end guy I must admit some of is beyond my current level of understanding...

    Now things are happening in the right area, the basic logic I'm trying to achieve on each category page is this:

    1. Find the current category ID
    2. Display the full content of the latest post within that category ID

    Sadly no matter how much I shout those instructions at Wordpress it doesn't work ;)

    Could some kind soul make my weekend explain how I'd do that with thematic/WP/PHP goodness?

    Posted 3 years ago #
  5. wait- are you looking to display the full content of the first post on the category page and then follow that w/ the normal excerpts? that is a different animal and would involve overriding the category loop like i originally thought, but with a counter. then you test for the counter being equal to 1, and for that post show the full content (the_content() ) in place of thematic_content which shows excerpts on archive pages by default.

    the category loop is shown in content-extensions.php in the thematic/library/extensions folder. copy the thematic_category_loop function into your child's functions.php and rename it childtheme_override_category_loop()

    if this is not the case and you are still doing what i was thinking above (though now that i think on it, won't you end up w/ the full post of something immediately followed by the excerpt for the same post?

    so while i don't think this what you're actually after anymore, it will show you how to get the category id .you don't have to shout- just know how to talk wordpress... which actually a quick google of 'get category id' or something similar reveals.

    function bacon(){
      $category = get_the_category();
    	$cat_id = $category[0]->cat_ID ;
    
    	$args = array('show_posts'=>1,'category'=>$cat_id);
    	$myposts = get_posts($args);
    
    	foreach( $myposts as $post ) :	setup_postdata($post); //from the get_posts codex 
    
    	thematic_postheader();
    	the_content();
    
    	endforeach;
    
    }
    add_action('thematic_above_categoryloop','bacon');
    Posted 3 years ago #
  6. Hi Helga - no you were right originally. I just want every category page to only show the last post (in full e.g. the_content) from that category.

    I commented out thematic_cateogoryloop() from my categories.php and added your code into the functions.php file.

    The good news is it's basically doing what I need. The content of the post is (and will always be) video in the form of a JWPlayer. At present I only see a thumbnail of the video and not the actual video but I think that is a problem with JWplayer more than anything else.

    Thanks for taking the time to help out! If you drop me a mail at contact at benfrain.com I'd love to Paypal you a virtual beer/hot beverage to say thanks.

    Posted 3 years ago #
  7. ok- just so you know, it isn't advisable to edit the thematic core files. around here we recommend that you make edits via the functions.php of your child theme... or possibly through copying the template (aka categories.php in this case) into your child theme folder.

    child theming is great imo, b/c you only have to change the bits you want to change and also b/c the core theme can upgrade w/o (usually) borking your site or losing your changes.

    Posted 3 years ago #
  8. Hi Helga! Can you enlight me?

    This exactly what I was looking display the full content of the first post on the category page and then the following post related to the category

    I tried as you say, but I still do not know how to limit the loop

    function childtheme_override_category_loop() {
    query_posts('&showpost=1');
    while (have_posts()) : the_post();

    thematic_abovepost(); ?>

    <div id="post-<?php the_ID();
    echo '" ';
    if (!(THEMATIC_COMPATIBLE_POST_CLASS)) {
    post_class();
    echo '>';
    } else {
    echo 'class="';
    thematic_post_class();
    echo '">';
    }
    thematic_postheader(); ?>
    <div class="entry-content">
    <?php the_content(); ?>

    </div><!-- .entry-content -->
    <?php thematic_postfooter(); ?>
    </div><!-- #post -->

    <?php

    thematic_belowpost();

    endwhile;
    }

    I tried this, but I lost the category ID when I add the post limit to one in this line

    query_posts('&showpost=1');

    Posted 3 years ago #
  9. because you overwrote your original query parameters. to merge your adjustments in with the original query you need to use wp_parse_args

    global $wp_query;
    $my_args = array( 'posts_per_page' => 10000 );
    $args = wp_parse_args( $my_args, $wp_query->query);
    
    query_posts($args)
    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.