0

Hi i'm trying to change the home page, because i'd like to have a slider and down only one category of article.

you can look at the page on line: http://goaboa.it/home-2014/

I cannot see anything articles in the homepage...

Can you help me to change correctly the code, to show only category with ID 17, called "home2014".

you can see the code about my new template here:

<?php
/*
Template Name: HOME 2014 BIS
*/
?>

<?php get_header(); ?>

<section id="omc-main">    




<?php
      $displayed = false;
      if (function_exists('shareit_output')) {
        $h_sticky = shareit_output();
        $home_page = get_option ('shareit_home', 0);
        if (!$displayed and $h_sticky && $home_page == 1) {
          echo $h_sticky;
          $displayed = true;
        }
      }
      ?>
    <?php get_template_part( 'loop', 'flexslider-homepage' ); ?>

    <?php     if ( have_posts() ) : while ( have_posts() ) : the_post();     ?>

        <?php the_content(); ?>        

    <?php endwhile; endif; ?>    

    <br class="clear" />




    <?php
foreach((get_the_category()) as $category) {
    echo $category->cat_ID . '17';
} ?>



    <?php // Category - Featured Slider
    $category_id = get_cat_ID( '17');
    $category_featured_enabled = get_tax_meta($category_ID,'omc_featured_slider');        
    if ($category_featured_enabled == 'on') { get_template_part('loop', 'module-flex'); } else { ?>



    <?php } ?>

    <?php // Determine whether to use a preset blog style or echo content (with shortcodes)

    $category_blog_style = get_tax_meta($category_ID,'omc_blog_style');        
    $category_content = get_tax_meta($category_ID,'omc_content_field_id');

    if ($category_blog_style == '') {        
        get_template_part('loop', 'blog-style-2');    
    } else if ($category_blog_style == 'shortcodes') {        
        echo do_shortcode($category_content);
    } else {        
        get_template_part('loop', $category_blog_style);        
    }
    ?>


</section><!-- /omc-main -->

<?php get_sidebar(); ?>

<?php get_footer(); ?>
  • 1
    Can you clarify your question some more? There are a lot of things happening in your template, I can't see which parts have the problem and which dont :s – Tom J Nowell Mar 26 '14 at 15:38
  • Also we will need to see the other template parts you're using here, such as 'loop', 'flexslider-homepage' – Tom J Nowell Mar 26 '14 at 15:39
1

Use pre_get_posts to modify the query before it is executed:

function include_category( $query ) {
    if ( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'cat', '17' );
    }
}
add_action( 'pre_get_posts', 'include_category' );
0

If you only want to include posts from a specific category in the loop, you may need to alter the query by using wp_query():

http://codex.wordpress.org/Class_Reference/WP_Query

Something like this:

$query = new WP_Query( 'cat=17' );

// The Loop
if ( $the_query->have_posts() ) {
if ( have_posts() ) : while ( have_posts() ) : the_post();

     the_content();         

endwhile; endif;  
} else {// no posts found}

/* Restore original Post Data */
wp_reset_postdata();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.