• I am trying to make my main webpage be a list of the posts in my news category. I have 2 ideas but not getting either to work right. If anyone can help me make either one work that would be great.

    #1 Is I made a news page and I created a template based of my decoder template. I changed the query to as follows:

    <?php
    $cat = array(1);

    $showposts = -1; // -1 shows all posts
    $do_not_show_stickies = 1; // 0 to show stickies
    $args=array(
    ‘category__in’ => $cat,
    ‘showposts’ => $showposts,
    ‘caller_get_posts’ => $do_not_show_stickies
    );
    $my_query = new WP_Query($args);

    ?>
    I would really rather the catagory be the word news but I haven’t tried that yet. So when I do this if i visit the news page I see only 1 of the 2 news posts. So something isn’t quite right there. -1 is supposed to mean how many. I tried setting it to 10 also but no difference.

    The 2nd thing I could do is Make the news category link on the top bar my home page. I don’t know how to do that.

    Finally depending on which one I go with, I will need to hide a category or I will have a home and a news which is redundant. I found a plugin to hide categories but it appeared to have an error and I think it hides it from much more then just the top list. I also tried editing header.php as follows:

    <?php wp_list_categories(‘title_li=&sort_column=menu_order exclude=1’); ?>

    I tried exclude 0 or 1 and saw no difference.

    Any thoughts?

Viewing 8 replies - 1 through 8 (of 8 total)
  • No need to reinvent the wheel:

    http://codex.wordpress.org/Template_Tags/query_posts
    http://codex.wordpress.org/Tag_Templates

    Let me know if that helps or if you need more guidance.

    Thread Starter greyhoundgames

    (@greyhoundgames)

    Ok i see what this is saying. Maybe I have a terminology confusion though. Whats teh difference between a template page and a tag template?

    I am thinking I am supposed to do:
    if (is_home()) {
    query_posts(“category_name=news”);
    }

    and put this in my page.php

    Is that right? Then do away with the template I created. If that’s correct, do you know how I can then hide my news category so that home and news are not the same?
    Thanks.

    Whats teh difference between a template page and a tag template?

    A page template controls how some (or all) WordPress Pages are displayed. A tag template controls how a web page containing all posts with a particular tag are displayed.
    A template just refers to nay file that controls the display of specific WordPress objects or archive types – sidebars (menus), category displays etc.

    This might help:

    http://codex.wordpress.org/Theme_Development#Anatomy_of_a_Theme

    What you want to do can be done either with a separate template page or just with a query as you’ve done.

    A “template page” is only REALLY necessary if you want to change the physical aspects of that page, not just the post categories/etc it displays.

    Otherwise, if you’re just changing what posts show up, it can all be done with if/else/etc queries I believe.

    I’m somewhat confused now… you want news on the home page but you don’t want news on the news page… or maybe you don’t want a “news” page at all. Let me see if I understand what’s going on here…

    I’m going to guess that your theme is using wp_list_categories to generate your navigation links. If this is correct, then you can use the query you’ve already made* on your index.php to actually exclude the post themselves and then I think all you need to do is exclude the news category # itself from the wp_get_categories tag that your navigation is using…

    Here’s a link to another support thing on how to find the actual category’s number for use in the code.

    *Note: You probably need to use single quotes in your query rather than double ones, like so:

    if (is_home()) {
    query_posts('category_name=news');
    }

    Thread Starter greyhoundgames

    (@greyhoundgames)

    Thanks guys. I got it working how I need. To recap the changes incase I didn’t do it the best way:
    index.php(instead of page.php since its the home now and not a page)
    changed the top of the file too:
    <?php get_header();
    if (is_home()) {
    query_posts(‘category_name=News’);
    }
    ?>

    Changed header.php:
    <?php wp_list_categories(‘title_li=&sort_column=menu_order&exclude=4’); ?>

    Really appreciate the quick responses! The overall goal was a way to have news show up on the home page, and nowhere else as well as avoiding any redundant links\navs\pages etc.

    Thread Starter greyhoundgames

    (@greyhoundgames)

    Hmm.. I noticed that my category order does not reflect what I set in the plugin i added to organize categories. My Category Order. Is this because of my changes. If so I can problematically order them if that’s possible.

    Thread Starter greyhoundgames

    (@greyhoundgames)

    I also tried removing the sort_column=menu_order. I think if i remove that plugin and just find how to change the ID of a category I should be good as I can sort by ID.

    Thread Starter greyhoundgames

    (@greyhoundgames)

    Sorry for the spamminess. I figured it out. I guessed that my plugin requires the sort to be on ID and not name so i changed it to
    <?php wp_list_categories(‘orderby=ID&order=ASC&title_li=&exclude=4’); ?>
    and all works fine.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘New to wp but not scripting’ is closed to new replies.