WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to use category as homepage (12 posts)

  1. itsalltech
    Member
    Posted 4 years ago #

    Hello.

    I am wondering if it would be possible to use a category as the homepage to my site. Right now, the homepage is "Home" and it contains all the posts. However, I would like it to be the category "News". Any ideas on how to do this? But, I still want to only have to type in "itsalltech.com" not "itsalltech.com/category/news". Thanks.

    http://www.itsalltech.com

  2. SimonJ
    Member
    Posted 4 years ago #

    Hola

    [1] Learn how to make a wordpress page template

    [2] Make a page template with a query_post for a specific category

    [3] Use a page with this page template as an home page in your WP options.

    Look there for more information :

    http://wordpress.org/support/topic/227151?replies=9
    http://wordpress.org/support/topic/156208?replies=7

    @+

    S.

  3. Mark / t31os
    Moderator
    Posted 4 years ago #

    You don't even need to do that, a simple conditional query_posts in the theme's index like so should suffice, to keep it simple...

    if( is_home() ) {
    	$args = array( 'category__in' => array(1) );
    	$args = ( $wp_query && $wp_query->query ) ? array_merge( $wp_query->query , $args ) : $args;
    	query_posts( $args );
    }

    Update the 1 in array(1), to the ID of the category.

    The same could be done with just..

    if( is_home() ) query_posts( 'cat=1' );

    ..however it doesn't account for preserving any query vars that exist for the query.. hence the slightly bulkier version above which should keep you covered.

    If that all seems too much at all, see the reply above mine.. ;)

  4. itsalltech
    Member
    Posted 4 years ago #

    So, where would I post the `if( is_home() ) {
    $args = array( 'category__in' => array(1) );
    $args = ( $wp_query && $wp_query->query ) ? array_merge( $wp_query->query , $args ) : $args;
    query_posts( $args );
    }`

    in the index.php file?

  5. SimonJ
    Member
    Posted 4 years ago #

    Another very simple solution...

    Use the home.php template file with a query_post from the category you wish to display...

    :-)

    S.

  6. itsalltech
    Member
    Posted 4 years ago #

    I don't have a home.php on my theme. Would that be index.php?

  7. SimonJ
    Member
    Posted 4 years ago #

    Juste make a copy of your index.php and rename it home.php...

    Then, edit this file (home.php) to make a loop with query_post...

    It should do the trick.

    S.

  8. Mark / t31os
    Moderator
    Posted 4 years ago #

    Yes or that, there's usually lots of ways to do the same thing... :)

    There's also the pre_get_posts method, but let's not confuse a simple task for OP and leave that for another discussion..

  9. itsalltech
    Member
    Posted 4 years ago #

    It's stil not working. When I try to add that code into index.php or even home.php, it just shows up as code in the browser.

  10. Mark / t31os
    Moderator
    Posted 4 years ago #

    It's stil not working.

    Without knowing which method you're trying to use, it's hard to know how to help you, are you referring to the code i supplied further up?

    If so, you would need to ensure the code is placed inside the opening and closing PHP tags..

    This

    <?php

    and this..

    ?>

    Else, it's going into the HTML section of the document which will just output the PHP code as text....

    To make things easier, you could just provide a copy of the file you want to adjust.

    http://wordpress.pastebin.ca/
    NOTE: This is a site for pasting code into, use this in place of the forum (especially for large pieces of code), and report the URL provided back here.

    I'll then provide an updated version of the code to replace your existing one with, since it's only a very minor change...

  11. itsalltech
    Member
    Posted 4 years ago #

    Thank You! That was it, I did not put it in the PHP code. It works. Thanks for the help.

  12. Mark / t31os
    Moderator
    Posted 4 years ago #

    No worries, you're welcome.. ;)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.