WordPress.org

Support

Support » How-To and Troubleshooting » Getting a Particular category showing up on home page

Getting a Particular category showing up on home page

  • I have a customized template that I am using and I am trying to get post from just one category to show on the front page. The code that is there looks like this:

    <?php if (Themehave_random_posts()) : ?>
    			<?php while (Themehave_random_posts()) : $theme_queryRandom->the_post();
    				if(!@in_array(get_the_ID(), $showedPosts)){?>

    What would I change to control the category?

Viewing 9 replies - 1 through 9 (of 9 total)
  • That’s a custom function (i think), refer to your theme’s functions.php.

    Looking in functions I found this….`function Themehave_random_posts(){
    global $wp_query, $shortname, $theme_queryRandom, $wpdb, $cx, $showedPosts, $ids;
    if(!$theme_queryRandom){
    $show = (int)get_settings($shortname.”_randomCategoryPosts”);
    if(!in_array($show, $ids))
    $ids[] = $show;
    $theme_queryRandom = new WP_Query(‘category_name=’.get_cat_name($show).’&orderby=rand&showposts=1′);
    }
    $aux = $theme_queryRandom->have_posts();
    if(get_the_ID())
    $showedPosts[] = get_the_ID();
    return $aux;
    }`

    Now Im more confused.

    This part is a custom query…

    WP_Query('category_name='.get_cat_name($show).'&orderby=rand&showposts=1');

    You should, and i say ‘should’ be able to just edit that line to read…

    WP_Query('category_name='.get_cat_name($show).'&orderby=rand&showposts=1&exclude=1,2,3');

    Example above excludes categries 1, 2 and 3, if you wanted to exclude category 38 for example you’d do…

    WP_Query('category_name='.get_cat_name($show).'&orderby=rand&showposts=1&exclude=38');

    When I exclude the categories I dont want I get this error

    Fatal error: Call to undefined function themehave_random_posts() in /backup/taaluxur/public_html/homes/wp-content/themes/freshblue-idea-10/home.php on line 6

    It works if that change is not made though?

    The error suggests that it does not recognise the custom function.

    Yes, it works fine. line 6 is of course the intial code in post. Does something need to be changed there too for these to work together?

    Not sure how it would mesh with your custom template, but would a plugin work for you? Advanced Category Excluder lets you exclude categories from pages.

    I appreciate the links but they coding examples are over my head. Ill try to plug in. But since this is semi custom code I doubt it would work.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Getting a Particular category showing up on home page’ is closed to new replies.
Skip to toolbar