Set the background to a default image if there isn’t a specified “featured image”

I found the solution from a WordPress forum and this is what they used. Works perfect <?php if (has_post_thumbnail( $post->ID ) ): ?> <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), ” ); $image = $image[0]; ?> <?php else : $image = get_bloginfo(‘stylesheet_directory’) . ‘/lib/images/home1-1024×681.jpg’; ?> <?php endif; ?> <section id=”halfpro” style=”background-image: url(‘<?php echo $image; ?>’)” … Read more

Extending the WP_Widget_Text class

Think about it, why would WordPress do anything just because you have defined additional class? It’s not magic (neither magical magic or code driven magic). The text widget doesn’t appear simply because class exists. When WordPress loads it runs wp_widgets_init(), which executes register_widget(‘WP_Widget_Text’). So technically you cannot tell it to use different class. What you … Read more

Increase returned number/pages on pagination

Refer to the Codex page for paginate_links for all accepted arguments. The two you want to modify are mid_size and possibly end_size. $output .= paginate_links( array( ‘base’ => str_replace( $big, ‘%#%’, esc_url( get_pagenum_link( $big ) ) ), ‘format’ => ‘?paged=%#%’, ‘current’ => max( 1, get_query_var(‘paged’) ), ‘total’ => $wp_query->max_num_pages, ‘mid_size’ => 8 // number of … Read more

Converting HTML Template to WordPress Theme

As said, you should enqueue your style sheets like this in your functions.php in your theme: function adds_to_the_head() { // Our own unique function called adds_to_the_head wp_register_style( ‘custom-style-css’, get_stylesheet_directory_uri() . ‘/css/styles.css’,”,”, ‘screen’ ); // Register style.css wp_enqueue_style( ‘custom-style-css’ ); // Enqueue our stylesheet } add_action( ‘wp_enqueue_scripts’, ‘adds_to_the_head’ );

wordpress count link clicks by ip address

What would you do if the user uses a proxy and randomizes his IP address? There are numerous browser plugins to simplify that to a click of a button to download multiple times. The same goes for cookies. Aside from that you are trying to collect data that allows to identify users, which is illegal … Read more

WSoD being caused by this piece of code

You have a problem with your code formatting and syntax at the very least: function ref_access(){ global $error; if (is_user_logged_in()) // <– problem here… $newdb = new wpdb( ‘user’, ‘pass’, ‘db’, ‘localhost’ ); global $newdb; $hf_username = wp_get_current_user(); $inputValue = $_POST[$quanid]; $wpdb->insert( $table, array( ‘ItemID’ => $quanid ‘Price’ => $inputValue ‘user’ => $hf_username ), ); … Read more

Get updated query results on page after insert in database

Move insert query to top of file. So it will select updated data. <?php // Save form data if(isset($_POST[‘submit’])){ global $wpdb; $votes = 1; $competition = $_POST[‘comp’]; $uid = $_POST[‘id’]; //$uid = get_current_user_id(); echo ‘id of image=”.$_POST[“id’]; echo ‘<br>’.’competition is’.$_POST[‘comp’]; if($wpdb->insert( ‘votes’, array( ‘votes’ => $votes, ‘competition’ => $competition, ‘uid’ => $uid ) ) == … Read more