WordPress.org

Ready to get started?Download WordPress

Forums

Academica
[resolved] Home page show posts from one category only (8 posts)

  1. Pali Madra
    Member
    Posted 7 months ago #

    The theme is the right fit for my present requirements and works well.

    There is one issue that I cannot fix and that is that I wanted to show posts from one category only on the home page. However, I have not been able to customize this.

    Any help would be appreciated.

  2. esmi
    Theme Diva & Forum Moderator
    Posted 7 months ago #

    First create a child theme for your changes. Then you will need to add a custom query to your theme's main posts page (possibly index.php). See http://codex.wordpress.org/Function_Reference/query_posts

  3. Pali Madra
    Member
    Posted 7 months ago #

    Thanks.

    Esmi to the rescue as is the case usually! :-)

    I mean the WordPress forum would not be what it is if you were not around.

    Thank you for finding the solution as creating a child theme did not come to my mind and it would work in most cases.

    However, if it is not too much of a hassle can you let me know where the loop is being run in the theme. The reason I'm asking is purely for knowledge as the Academica theme does not have a typical structure one has come to expect from WordPress themes.

    Thanks for the help. It inspires me to spend sometime giving back to the WordPress community.

  4. esmi
    Theme Diva & Forum Moderator
    Posted 7 months ago #

    Looking at the theme's files in SVN, it seems that the index.php template file is indeed the one that you want. That's where the Loop is set up, so you'll need to add your custom query just before:

    <?php
    if ( have_posts() ) :

    A rather more elegant & future-proofed solution would be to add something like:

    function my_home_category( $query ) {
        if ( $query->is_home() && $query->is_main_query() ) {
            $query->set( 'cat', '123' );
        }
    }
    add_action( 'pre_get_posts', 'my-home_category' );

    in your child theme's functions.php file - where 123 is the id of the category that you want to display. In theory, that should also work.

  5. Pali Madra
    Member
    Posted 7 months ago #

    As I said esmi you are awesome (for lack of a better word)!

    PS: are you there on Twitter or FB..... maybe I can learn more from there!

  6. esmi
    Theme Diva & Forum Moderator
    Posted 7 months ago #

    Sadly, I am obviously too anti-social to use either Twitter or FB. I do post occasionally on http://quirm.net/ if that helps :-)

  7. Pali Madra
    Member
    Posted 7 months ago #

    Anti-social? You? though people may assume that because you do not have social accounts but the truth is far too different. I do follow the blog at quirm.net and it has some of the most useful posts.

    Thanks for your time. Appreciate it.

  8. esmi
    Theme Diva & Forum Moderator
    Posted 7 months ago #

    Thank you. I am suitably flattered. :-)

Reply

You must log in to post.

About this Theme

About this Topic