Display all posts from specific categories on a page

I’d Advise adding the arg of the category in an array. And don’t use query_posts. Also showposts is deprecated use posts_per_page instead. $args = array ( ‘cat’ => array(2,6,9,13), ‘posts_per_page’ => -1, //showposts is deprecated ‘orderby’ => ‘date’ //You can specify more filters to get the data ); $cat_posts = new WP_query($args); if ($cat_posts->have_posts()) : … Read more

disable WP automatically inserted line breaks after an image

If this is how it looks: <img class=”alignleft size-medium wp-image-8530″ alt=”…” src=”#” width=”413″ height=”275″ /> <img class=”alignleft size-medium wp-image-8529″ alt=”…” src=”#” width=”413″ height=”275″ /> Then you have to put them together like this: <img class=”alignleft size-medium wp-image-8530″ alt=”…” src=”#” width=”413″ height=”275″ /><img class=”alignleft size-medium wp-image-8529″ alt=”…” src=”#” width=”413″ height=”275″ /> Because if you do this … Read more

“coming soon” placeholder blog posts?

You can add a filter to ‘loop_start’, count how may posts you have and inject the needed number of “fake” posts that are intances of WP_Post not having a reference in DB. add_filter( ‘loop_start’, function( $query ) { $module = $query->post_count % 6; $to_fill = $module === 0 ? 0 : 6 – $module ; … Read more

How to get Images included in Post

You can use get_posts() (Codex ref for getting Post attachments). <?php $args = array( ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘numberposts’ => -1, ‘post_status’ => null, ‘post_parent’ => $post->ID ); $attached_images = get_posts( $args ); ?>

Sends out email to admin

No need for plugin here are a few lines of code you can modify and paste in your themes functions.php file and you will get a new email whenever a post is published: add_action(‘publish_post’, ‘send_admin_email’); function send_admin_email($post_id){ $to = ‘[email protected]’; $subject=”mail subject here”; $message = “your message here ex: new post published at: “.get_permalink($post_id); wp_mail($to, … Read more

Number of post for a WordPress archive page

paste this in your theme function.php file add_filter(‘pre_get_posts’, ‘Per_category_basis’); function Per_category_basis($query){ if ($query->is_category) { // category named ‘books’ show 12 posts if (is_category(‘books’){ $query->set(‘posts_per_page’, 12); } // category With ID = 32 show only 5 posts if (is_category(’32’){ $query->set(‘posts_per_page’, 5); } } return $query; } explanation: first we check if its actually a category because … Read more

Post/Page Publish/Update button not clickable once I make an edit

It appears to be a bug, but one that can be hacked around each time it happens with about 2 seconds of work. This wordpress forum thread: If you’re using Chrome, right-click on the greyed-out “Update” button and select “Inspect Element”. You will see something to the likes of: <input name=”save” type=”submit” class=”button button-primary button-large … Read more

Using single.php from plugin folder instead of default template folder

I think a hook into template_include like described here could be a proper way to do this. Code could be like this: add_filter(‘template_include’, ‘my_plugin_templates’); function my_plugin_templates( $template ) { $post_types = array(‘post’); if (is_singular($post_types)) { $template=”path/to/singular/template/in/plugin/folder.php”; } return $template; }

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)