ThemeShaper Forums » Thematic

[closed]

Adding a list of recent posts to a custom page template

(23 posts)
  • Started 3 years ago by Direct Sponsor
  • Latest reply from helgatheviking
  • This topic is resolved
  1. This should be simple enough:

    I want to add a list of my recent posts to a custom page template i.e. entry-title, entry-meta, entry-content, entry-utility etc...

    It should read just like the loop of chronological posts found in index.php.

    How should I do this? I've tried copying and pasting from the content extensions files but I'm getting errors about redeclarations.

    Posted 3 years ago #
  2. you need a loop with get_posts

    http://codex.wordpress.org/Template_Tags/get_posts

    Posted 3 years ago #
  3. Thanks Helga. I've implemented the following based on your suggestion:

    <?php
    $args = array( 'posts_per_page' => 10, 'order'=> 'ASC', 'orderby' => 'title' );
    $postslist = get_posts( $args );
    foreach ($postslist as $post) :  setup_postdata($post); ?>
    	<div>
    		<?php the_date(); ?>
    
    		<?php the_title(); ?>
    		<?php the_excerpt(); ?>
    	</div>
    <?php endforeach; ?>

    Is there a particular Thematic function I can call on so it outputs (and thusly styles) the post list in the exact same way as my Thematic index page?

    I've tried using the example at the below link but I can't get it to work:
    http://themeshaper.com/wordpress-theme-index-template-tutorial/

    Posted 3 years ago #
  4. yes, try the link above for get_posts. has many different options.
    to put you on your way.. something like this would keep the styling you require (entry-title, entry-meta, entry-content, entry-utility etc...)

    global $post;
    $args = array( 'numberposts' => 5, 'order'=> 'DESC' );
    $myposts = get_posts( $args );
    foreach( $myposts as $post ) :	setup_postdata($post); ?>
    
    <div id="post-<?php the_ID(); ?>" class="<?php thematic_post_class(); ?>">
    <?php thematic_postheader(); ?>
    <div class="entry-content">
    <?php thematic_content(); ?>
    </div><!-- .entry-content -->
    <?php thematic_postfooter(); ?>
    </div><!-- #post -->
    
    <?php endforeach; ?>

    this will grab the latest 5 posts in desc order.
    hope this helps

    Posted 3 years ago #
  5. just posted this after you replied.
    you'll see the above

    <div id="post-<?php the_ID(); ?>" class="<?php thematic_post_class(); ?>">
    <?php thematic_postheader(); ?>
    <div class="entry-content">
    <?php thematic_content(); ?>
    </div><!-- .entry-content -->
    <?php thematic_postfooter(); ?>
    </div><!-- #post -->

    thats the hooks from the index loop that creates the various divs and styles for each section of the post

    Posted 3 years ago #
  6. The following excerpt from content-extensions.php (lines 441-458) seems to (mostly) do the trick:

    <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 thematic_content(); ?>

    <?php wp_link_pages('before=<div class="page-link">' .__('Pages:', 'thematic') . '&after=</div>') ?>
    </div><!-- .entry-content -->
    <?php thematic_postfooter(); ?>
    </div><!-- #post -->

    Some of the CSS is a little off, the thumbnails and excerpts aren't applied but I'm confidant that I can reverse (or forward I guess) engineer from here.

    Posted 3 years ago #
  7. Thanks Jonny. Your suggestion achieves the exact same as the code in my previous post but with less code. Onwards to functions.php and style.php to figure out why a minority of the filters/hooks/style aren't applying :-)

    Thanks for the help from you both! It's greatly appreciated.

    Posted 3 years ago #
  8. i think we were posting at the exact same time.
    glad you found a solution.

    the styles shouldn't differ, unless the latest posts is nested within styles you've alredy created for the new template. otherwise, i tested it and all remained the same.

    and just to note, in the code i provided

    <?php thematic_post_class(); ?>

    thats exclude the 'if function' exists, so if you haven't disbaled 'thematic post class' all will be ok, but if you decide not to use this function, you would need to ammend.

    hope all works out

    Posted 3 years ago #
  9. Hmm, can't find where the thematic_post_class function is defined so I doubt I disabled it seeing as how I don't what it is. Is it safe to assume I need not amend?

    With the code you suggested, a few simple filters aren't being applied:

    // Part 1: Home/front page posts to excerpts.
    function childtheme_content($content) {
    if (is_home() || is_front_page() || is_page('home')) {
    $content= 'excerpt';}
    return $content;
    }
    add_filter('thematic_content', 'childtheme_content');
    
    // Part 2: String replace the ellipse with a read more link.
    function excerpt_ellipse($text) {
       return str_replace('[...]', ' [...]</br><a href="'.get_permalink().'">
    <img src="/images/button-readmore.png" style="margin-top:10px; display:block;"/></a>', $text); }
    add_filter('the_excerpt', 'excerpt_ellipse');
    
    // Part 3: Define excerpt length.
    function new_excerpt_length($length) {
    return 80;
    }
    add_filter('excerpt_length', 'new_excerpt_length');

    Any ideas what I'm missing? The page name is 'Home' and the page template name is 'template-home'.

    Might the name 'home' be conflicting with something or is it because I'm missing some of the surrounding divs like #content?

    Posted 3 years ago #
  10. I've tried changing the page name from 'Home' to 'Home-test' in wp-admin > pages and by furthermore changing the filter from is_page('Home') to is_page('Home-test'). This hasn't had an effect so the issue isn't related to how I'm calling the page name in the function.

    is_page() doesn't work either.

    Nor does !is_single()

    Posted 3 years ago #
  11. It seems the problem is thematic_content not working with filters relating to excerpts.

    Another thread was started by another member 7 months ago: http://forums.themeshaper.com/topic/thematic_content-filter-not-working-properly

    The poster didn't get a response/fix.

    More here: http://forums.themeshaper.com/topic/how-do-i-replace-thematic_content

    ...and here: http://forums.themeshaper.com/topic/adding-a-loop#post-3684

    Can anybody explain why Thematic is ignoring thematic_content filters on page templates?

    Posted 3 years ago #
  12. I have run into it before, but can't remember where. (this is becoming a theme for me). it has to do w/ that function essentially running before WP knows what template is being used, so it will never satisfy your logic.

    keep searching i believe Gene answered my post on the subject- i think i was writing about creating new content types, but the template thing was relevant. i will google my brain to see if i can find that post...

    Posted 3 years ago #
  13. firstly,

    thematic_post_class

    so you know, thats just a dynamic class thematic adds to the #post. it extends classes for styling purposes.

    have you tried conditional tags for page-template
    is_page_template('blahblah.php')

    note: unlike with other conditionals, if you want to specify a particular Page Template, you need to use the filename, such as about.php or my_page_template.php

    that should sort problem (1) out, whether to use content or excerpt.

    i'll test the other filters you mention

    Posted 3 years ago #
  14. Still working on this.

    -----> @helga:

    You added a fix regarding the 'read more' link on excerpts but that's about all I've come across: http://forums.themeshaper.com/topic/enclosing-excerpt-in-paragraph-tag-038-adding-a-custom-read-more-link#post-13437

    These threads might refresh your memory:
    http://code.google.com/p/thematic/issues/detail?id=58
    http://forums.themeshaper.com/topic/filter-thematic_content-plus-custom-loop
    http://forums.themeshaper.com/topic/adding-a-loop#post-3684
    http://forums.themeshaper.com/topic/how-do-i-replace-thematic_content

    -----> @Jonny:

    Thanks for the thematic_post_class explanation. No go with is_page_template('template-home.php'). FYI Helga mentioned that WP doesn't recognize what template is being used (see post prior to yours).

    Posted 3 years ago #
  15. I've found the solution and yes, it was Gene (moderator) who provided a fix in different thread: http://forums.themeshaper.com/topic/how-do-i-replace-thematic_content

    The short answer, I was missing thematic_abovepost().

    The long answer:

    1. The thematic_content filter resides in thematic_content_init().
    2. thematic_content_init() is hooked to thematic_abovepost().
    3. Any custom loop therefore requires thematic_abovepost() to correctly apply thematic_content filters.

    @Jonny: The thematic_post_class() was of more relevance to the solution than I understood considering that it too is affected by the absence of thematic_abovepost().

    Thanks again to you both (and thanks to Gene of course).

    Posted 3 years ago #
  16. this isn't the thread i was thinking of:

    http://forums.themeshaper.com/topic/excerpt-on-front-page-childtheme_override_content_init-never-called

    but if the lack of thematic_aboveheader is the problem, then that has since been fixed in the SVN version of thematic. and therefore (probably) in the latest stable dev release which is available at chris' site:

    http://developing.thematic4you.com/thematic-development-release/

    also- google brain remembered the other post i was trying to reference:

    http://forums.themeshaper.com/topic/changing-content-of-excerpt-conditionally-and-editing-all-loops-at-once#post-14618

    though i think this is unnecessary if you are adding the function to thematic_aboveheader....

    Posted 3 years ago #
  17. ps- pertaining to excerpts i wrote a Class that I think is pretty damned fly:

    http://forums.themeshaper.com/topic/how-to-make-excerpts-roll-over-and-say-uncle

    Posted 3 years ago #
  18. @helga: Thanks for the links for further context.

    If you have the time, could you briefly explain the difference(s) between your excerpt function and the three step filter process I'm currently using: http://forums.themeshaper.com/topic/adding-a-list-of-recent-posts-to-a-custom-page-template#post-18202

    I can't recall the source of the filters I'm currently using but I'd like to understand the additional benefit(s) of your class.

    Posted 3 years ago #
  19. well the immediate difference from what you have is that you can set strip tags... ie the formatting tags that you would like to be allowed in an excerpt. this isn't exactly a big deal if you aren't dying to have links and bold text work in your excerpts. ;)

    the other difference would be if you needed to put excerpts of 2 difference sizes in different places in your theme. you could call kia_excerpt(20) in one place and kia_excerpt(40) somewhere else... which is not possible w/ default behavior.

    Posted 3 years ago #
  20. The second difference is definitely of benefit to me as I require some loops to read as excerpted paragraphs and others more like one-liner feeds. Cheers for the extra level of control :-)

    Posted 3 years ago #
  21. i'd love to make it sentence-aware, so if you have any insight or just want an extra problem to tackle....

    Posted 3 years ago #
  22. Without delving into the code the only thing I can think of is using specific characters as a trigger e.g. periods, exclamation marks, question marks or the first line break but you most likely already know this.

    The following link offers a decent overview for truncating text at word breaks and sentence breaks:
    http://www.the-art-of-web.com/php/truncate/

    It also offers a live editable demonstration of the truncation.

    Posted 3 years ago #
  23. thanks for the link. i will have to look into that. i know that the Fancy Excerpt plugin already does sentence-awaredness (fake word alert) so if i get super motivated i might be able to graft parts of that into my class. then i will truly have 1 excerpt class to rule them all.. and world domination will be mine.

    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.