Ready to get started?Download WordPress


Getting a Particular category showing up on home page (10 posts)

  1. montytx
    Posted 5 years ago #

    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?

  2. t31os
    Posted 5 years ago #

    That's a custom function (i think), refer to your theme's functions.php.

  3. montytx
    Posted 5 years ago #

    Looking in functions I found this....`function Themehave_random_posts(){
    global $wp_query, $shortname, $theme_queryRandom, $wpdb, $cx, $showedPosts, $ids;
    $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();
    $showedPosts[] = get_the_ID();
    return $aux;

    Now Im more confused.

  4. t31os
    Posted 5 years ago #

    This part is a custom query...


    You should, and i say 'should' be able to just edit that line to read...


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


  5. montytx
    Posted 5 years ago #

    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

  6. t31os
    Posted 5 years ago #

    It works if that change is not made though?

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

  7. montytx
    Posted 5 years ago #

    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?

  8. t31os
    Posted 5 years ago #

  9. asechrest
    Posted 5 years ago #

    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.

  10. montytx
    Posted 5 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic