Change layout of post depending on category

You can use the Conditional Tag in_category() within the loop: if( in_category( ‘events’ ) ): // output stuff for events category post else: // not in events category endif; Another option for single posts is to load a different template with a filter based on the category: function wpa8176_category_single_template( $template=”” ){ $categories = get_the_category(); foreach( … Read more

Get a post’s ID

If you’re on a singular page, sometime after init and all the query variables have all ben set up you can use get_queried_object_id or get_queried_object. <?php if (is_singular()) { $post_id = get_queried_object_id(); // or get the whole object $post = get_queried_object(); // or do the first one differently $post_id = get_queried_object()->ID; } You can also … Read more

Multiple Blog Pages

Check out the Codex page about creating your own page templates. The files defining each Page Template are found in your Themes directory under /wp-content. To create a new Custom Page Template for a Page you must create a file using a plain text editor (e.g Notepad or TextWrangler). Basically, create a php file, and … Read more

Getting posts from some categories plus some individual posts

The problem here is that WP_Query requires the posts returned to be both in your lists of post IDs and in one of your categories. The SQL query generated by your code looks something like this: SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND wp_posts.ID IN (8200,3581,38,1562,7613) AND … Read more

Showing posts for today and future

Use get_posts function with WP_Query params instead of get_children. The code will than look like this: $today = getdate(); $pages = get_posts( array( ‘post_status’ => array( ‘publish’, ‘future’ ), ‘post_type’ => ‘event’, ‘sort_order’ => ‘ASC’, ‘orderby’ => ‘date’, ‘year’ => $today[“year”], ‘monthnum’ => $today[“mon”], ‘day’ => $today[“mday”] ) ); foreach ( $pages as $post ) … Read more

Plugin is creating posts twice

The code does not adds posts twice – checked in my local installation. You have got errors in it: $my_post = array( ‘post_title’ => $title, ‘post_date’ => $insDate, ‘post_content’ => ‘$url’, ‘post_status’ => ‘public’, ‘post_type’ => ‘post’, ); Should be $my_post = array( ‘post_title’ => $title, ‘post_date’ => $insDate, ‘post_content’ => $url, ‘post_status’ => ‘publish’, … Read more

Trying to query all posts in category 4

For your issue regarding only returning 20% of your posts, try the following <?php query_posts(‘cat=4&posts_per_page=-1’); ?> Note: By default, 10 posts are returned. -1 will return all posts in the resulting set. http://codex.wordpress.org/Function_Reference/query_posts#All_Posts_in_a_Category — For your question about passing through the Category Name, you can pass through the category_name as parameter, which accepts the category … Read more

Limiting the amount of posts retrieved by the loop

The code you posted does not query for any content at all. To do that, use the WP_Query object. Please do not use query_posts, especially for secondary Loops. From the Codex: // The Query $the_query = new WP_Query( $args ); // The Loop while ( $the_query->have_posts() ) : $the_query->the_post(); echo ‘<li>’ . get_the_title() . ‘</li>’; … Read more