WordPress.org

Support

Support » How-To and Troubleshooting » How to combine two php

How to combine two php

  • Hello,
    I’d like to combine to php. but I don’t know how. The result should be that on the homepage will be displaying 5 posts and one category will be exluded.

    <?php
    if (is_home()) {
    query_posts("showposts=5");
    }
    ?>
    <?php
    if (is_home()) {
    query_posts("cat=-160");
    }
    ?>

    How do I combine it? Thank you!

Viewing 1 replies (of 1 total)
  • You simply add all the arguments you want. This is adapted from the WP_Query codex page:

    <?php
    
    // The Query
    $the_query = new WP_Query( 'cat=-160&posts_per_page=5' );
    
    // The Loop
    if ( $the_query->have_posts() ) {
            echo '<ul>';
    	while ( $the_query->have_posts() ) {
    		$the_query->the_post();
    		echo '<li>' . get_the_title() . '</li>';
    	}
            echo '</ul>';
    } else {
    	// no posts found
    }
    /* Restore original Post Data */
    wp_reset_postdata();
Viewing 1 replies (of 1 total)
  • The topic ‘How to combine two php’ is closed to new replies.