ThemeShaper Forums » Thematic

[closed]

Listing latest posts on a subpage via custom loop?

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

    Hello to the themeshaper community,

    first of all I have to thank everybody involved for this great framework. I'm new here and will definitively have to learn much, but untill I just can say you all have done great work, thanks!!

    Here's my question:

    I'm crafting a child theme and I want to show an unordered list of my newest ~12 posts on a sepcific page - just how it happens on every normal index.php, but I want to have it on my own-page.php (e.g.).

    I know that I can reach this goal by setting up a sepcific page template and writing all the neccessary code into that template. But as I read this article I thought it would be clever if I would define a custom loop via the functions.php of my child theme and just call this loop in the own-page.php. I followed all the steps from the article mentioned before and there are actual no errors. But, if i call the custom loop in the index.php, it runs as it should (showing the content of the newest wordpress articles), if I call it in the own-page.php, there just comes up the content of the wordpress page I set up and assigned the template to. The html code is rendered out correctely, directly from the custom loop i defined in the functions.php!

    So as far as I can think there must be a little piece of code I just have to add into the page template or functions.php to tell wordpress where to get the content from?? Does anybody has a clue or some tips where I can get ressources to understand this process?

    I'm a fairly beginner in wordpress so any helpfull answer is very appreciated!

    Pshhhht, I know my english is bad! I just learned it in school :x ;)

    Posted 8 years ago #
  2. thematic has a "blog" page template that displays your latest posts similarly to index.php. you can copy that template. "on a specific page" lends itself to using a page template. no real need to make it more difficult than that.

    you could also use get_posts() in your template
    http://codex.wordpress.org/Template_Tags/get_posts

    Posted 8 years ago #
  3. hanswurst
    Member

    Wow, thanks for this fast reply!

    It is just this one I need for my goals, right?


    <?php
    $wp_query = new WP_Query();
    $wp_query->query( array( 'posts_per_page' => get_option( 'posts_per_page' ), 'paged' => $paged ) );
    $more = 0;
    ?>

    Posted 8 years ago #
  4. hanswurst
    Member

    It is! It runs! Juchuuu! :D Thank youuu!

    So for anybody else who's reading this: If you want to call a custom loop you have defined in your functions.php on another page than the index.php (e.g. yourownpage.php), just take the following snippet from the template-page-blog.php (in your thematic parent theme folder) and paste it above your loop call, it should look something like this then:


    <?php
    /*
    Template Name: your page
    */
    ?>
    <?php

    // calling the header.php
    get_header();

    ?>

    <div id="container">
    <?php
    $wp_query = new WP_Query();
    $wp_query->query( array( 'posts_per_page' => get_option( 'posts_per_page' ), 'paged' => $paged ) );
    $more = 0;
    ?>

    <?php
    your_custom_loop_defined_in_functions.php-file();
    ?>

    </div>

    <?php
    // calling footer.php
    get_footer();
    ?>

    Correct me if I'm wrong.

    Posted 8 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.