ThemeShaper Forums » Thematic

[closed]

list of posts in a category

(10 posts)
  • Started 5 years ago by argie01
  • Latest reply from whatsthebigidea
  • This topic is resolved
  1. argie01
    Member

    Hi,

    I'm doing some styling modifications in Aether theme.
    So, I just want to show 1 post in frontpage, because I have a lists of categories at bottom.
    The problem with it is that when I configure 1 post in frontpage using options of WP, then when I click on a category to see the posts inside it I also get 1 post only. And in this case I'd like to get a list of the titles of my posts inside that category, or even better, a list of posts with a excerpt of their content.

    Conceptual question: I totally agree in using a framework as Thematic, but I don't understand how to do code modifications since I only have a file called functions.php in my theme :(

    Thank you for your help.

    Posted 5 years ago #
  2. Hi argie01,

    Welcome. Code modifications are done by creating functions and putting them in the functions file. Styling modifications are done in the child theme's style.css file.

    The beauty of using the Thematic frameowrk is that when new features are added, you can upgrade easily because all of your changes happen in the child theme, specifically in the child theme's style.css and functions.php files.

    What you're talking about above are changes to "The Loop" in WordPress. The way to change the behavior of this loop in Thematic is to create a function that overrides the standard Thematic loop. Any changes you'd like to your loop would be included in the loop function. The same goes for category pages.

    For instance, if I click a category on my install, it displays all the posts in that category. This happens because it's using a category loop...the same loop as above, but it's pulling posts by category. So, I had a need to change this behavior because I wanted to include some content inside the standard category loop. To do this, I had to create a function to override the category loop.

    Check it out:

    function remove_categoryloop() {
        remove_action('thematic_categoryloop', 'thematic_category_loop');
    }
    add_action('init', 'remove_categoryloop');
    
    function my_categoryloop() {
    while (have_posts()) : the_post(); ?>
    
              <div id="post-<?php the_ID(); ?>" class="<?php thematic_post_class(); ?>">
                  <?php thematic_postheader(); ?>
                       <div class="my-content">
                            This is my added content
                       </div>
                  <div class="entry-content">
    <?php thematic_content(); ?>
    </div>
                  <?php thematic_postfooter(); ?>
              </div><!-- .post -->
    
          <?php endwhile;
    }
    add_action('thematic_categoryloop', 'my_categoryloop');

    I plopped this into functions.php of my child theme, and now on my category pages I see "This is my added content".

    Make sense?

    I know this probably seems like a real pain in the rear, but once you get familiar with changing content like this, you'll be amazed at the possibilities. I can't tell you how many sites I've made where I've heavily edited the core theme files only to have the theme code break due to WP upgrades.

    Using the Thematic framework is preventative maintenance that will future-proof your sites.

    Posted 5 years ago #
  3. argie01
    Member

    Thank you for your answer! It's really scare me, because if I use Themathic I will also to learn to use WP and PHP code. Until now, I only knew html, css, an almost nothing other language else.
    If I understand you well, now I will have to know which are the php functions of WP and Thematic, and then modify them in functions.php of my child theme. And I will do it even in the caso I would add a simple "div" zone.

    Wow, this is hard.

    I will test your category function above... and I hope I could show a list of posts in each category.

    Thank you again!

    Posted 5 years ago #
  4. Thanks awarner20, but could you show me how to modify the category function so that I can control the order posts are displayed on category pages? I want to have them displayed in order of importance, which may change from time to time, not by when they were posted.

    Posted 5 years ago #
  5. Hi daveread,

    What is determining the importance of posts? This will be interesting reading for you: http://perishablepress.com/press/2008/01/22/6-ways-to-customize-wordpress-post-order/

    Once you decide how you want to order your posts, you would put this into a function that filters the category loop. See here for an example: http://forums.themeshaper.com/topic/can-i-target-hentry-for-only-category-archive-pages

    Please post back with your results so that we may all benefit...or help further:)

    Posted 5 years ago #
  6. The AStickyPostOrderER plugin, from the perishablepress.com article cited above, does the job. What I couldn't do with your functions solution was modify the orderby query string. Thanks awarner20, and I'll be back, especially interested in learning more about functions.

    Posted 5 years ago #
  7. I'm glad that the plugin was able to accomplish what you needed.

    p.s. I'm still learning functions also;)

    Posted 5 years ago #
  8. I've found a pretty elegant solution using the postMash(filtered) plugin

    I like the ease of re-ordering that this plugin offers compared with the other solutions like AStickyPostOrderER.

    The only thing you have to do to get postMash(filtered) working with Thematic is to add this filter in your functions.php:

    function postMash_orderPosts($orderBy) {
    global $wpdb;
    $orderBy = "{$wpdb->posts}.menu_order ASC";
    return($orderBy);
    }
    
    add_filter('posts_orderby', 'postMash_orderPosts');

    I hope that helps others that are still looking for a good solution to re-order posts.

    Cheers,
    Jonah

    Posted 5 years ago #
  9. Hi all,

    Anyone know how to reset the above if for example I have one category where I want to be able to control the order like above and another category where I want the order to be something else?

    I've tried using some conditional is_category() code but am coming up with some odd results.

    Any help would be appreciated.

    Thanks,
    Jonah

    Posted 4 years ago #
  10. I've used the above code with thumbnail using timthumb.php:

    //Get the First Image
    function catch_that_image()
    {
    global $post, $posts;
    $first_img = '';
    $url = get_bloginfo('url');
    ob_start();
    ob_end_clean();
    $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->
    post_content, $matches);
    $first_img = $matches[1][0];

    $not_broken = @fopen("$first_img", "r"); // checks if the image exists
    if (empty($first_img) || !($not_broken)) { //Defines a default image
    unset($first_img);
    } else {
    $first_img = str_replace($url, '', $first_img);
    }
    return $first_img;
    }
    function remove_categoryloop()
    {
    remove_action('thematic_categoryloop', 'thematic_category_loop');
    }
    add_action('init', 'remove_categoryloop');

    function my_categoryloop()
    {
    while (have_posts()):
    the_post(); ?>

    <div id="post-<?php the_ID(); ?>" class="<?php thematic_post_class(); ?>">
    <?php thematic_postheader(); ?>
    <?php if (catch_that_image()) { ?>
    <!-- Begin Thumb Container -->
    <div class="postthumb">
    ">
    <img src="<?php bloginfo('stylesheet_directory'); ?>/scripts/timthumb.php?src=<?php echo
    catch_that_image() ?>&w=75&h=75&zc=1&q=100" alt="<?php the_title(); ?>"/>

    </div><!-- End Thumb Container -->
    <?php }
    ; ?>
    <div class="entry-content">
    <?php thematic_content(); ?>
    </div>
    <?php thematic_postfooter(); ?>
    </div><!-- .post -->

    <?php endwhile;
    }
    add_action('thematic_categoryloop', 'my_categoryloop');

    Obviously you'll have to install timthumb.php and required cache folder as per timthumb installation instructions.

    Just wanted to share. I'm not a php coder so any questions to me may go unanswered.

    Posted 4 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.