simple wp_insert_post example

// Create post object $my_post = array(); $my_post[‘post_title’] = ‘My post’; $my_post[‘post_content’] = ‘This is my post.’; $my_post[‘post_status’] = ‘publish’; $my_post[‘post_author’] = 1; $my_post[‘post_category’] = array(0); // Insert the post into the database wp_insert_post( $my_post );” This works fine. You code is correct, but it is an problem in the form to send the $_POST … Read more

How to rotate the header image per day?

<div id=”header”> <?php mt_srand((int)date(‘z’)); $headers=glob(PATH_TO_FILES .’/*.jpg’); $header=mt_rand(0,count($headers)-1 ); ?> <img id=”header-image” `src=”https://wordpress.stackexchange.com/questions/5232/<?php echo URL_TO_FILES .”https://wordpress.stackexchange.com/”.basename($headers[$header]); ?>” alt=”header” /> </div> replace your current header with this. I will of course help you implement this further if you need help. (or if you need the code explained)

page_template toggle between 2 templates + 2 permalinks for same post

WordPress has a simpler function for what you’re trying to do, add_rewrite_endpoint. Additionally, the filter for a single post template is single_template, page_template fires on the page post type. function wpd_detail_endpoint(){ add_rewrite_endpoint( ‘detail’, EP_PERMALINK ); } add_action( ‘init’, ‘wpd_detail_endpoint’ ); function wpd_detail_template( $template=”” ) { global $wp_query; if( ! array_key_exists( ‘detail’, $wp_query->query_vars ) ) return … Read more

Looking to display non-image files in Gallery with logo specific to file type

WordPress has a native function wp_mime_type_icon() in wp-includes/post.php that you can use. Basic example: // $attachment should be a full post object if ( wp_attachment_is_image( $attachment->ID ) ) { echo wp_get_attachment_image( $attachment->ID, array( 480, 900 ), FALSE, array ( ‘class’ => ‘aligncenter’ ) ); } else { echo ‘<img src=”‘ . wp_mime_type_icon( $attachment->post_mime_type ) . … Read more

media_handle_upload weird thing

Look into the first lines of this function: function media_handle_upload( $file_id, $post_id, $post_data = array(), $overrides = array( ‘test_form’ => false ) ) { $time = current_time(‘mysql’); if ( $post = get_post($post_id) ) { if ( substr( $post->post_date, 0, 4 ) > 0 ) $time = $post->post_date; } $name = $_FILES[$file_id][‘name’]; $file = wp_handle_upload($_FILES[$file_id], $overrides, … Read more

How to exclude certain widget from showing up on home/front page? [duplicate]

I’ve found the exact solution to my question here: https://wordpress.stackexchange.com/a/17687/92505 Here’s the exact code I used after some modification to make it work on my situation. Add the following code to functions.php where ‘sidebar-1’ is your sidebar ID. ‘recent-posts’ is the name of the widget your want yo hide. 12 is the length of the … Read more

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