Shortcode inside custom post with pagination

function snowreports_shortcode($atts){
    extract( shortcode_atts( array(
        'count' => 10,
    ), $atts) );
    $i = 0;
    $q = new WP_Query(
        array(
            'posts_per_page' => $count, 
            'post_type' => 'posttype', 
            'paged'     => get_query_var('paged'),
        )
    );      
         
    $list = '<div class="custom-post-list">';
    while($q->have_posts()) : $q->the_post();
        $idd = get_the_ID();
        $i++;
        $custom_field = get_post_meta($idd, 'custom_field', true);
        $post_content = get_the_excerpt();
        $list .= '
        <div class="single-post-item">
            <h2><a href="'.get_permalink().'">' .do_shortcode( get_the_title() ). '</a></h2>
            '.wpautop( $post_content ).'
        </div>
        ';        
    endwhile;
    
    $total_pages = $q->max_num_pages;
    $big = 999999999;
    if ($total_pages > 1){  
        $current_page = max(1, get_query_var('paged'));  
        $list.= '<nav class="page-nav">';  
        $list.= paginate_links(array(  
            'base'      => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
            'format'    => '?paged=%#%',  
            'current'   => $current_page,  
            'total'     => $total_pages,  
            'prev_text' => 'Prev',  
            'next_text' => 'Next'  
        ));  
        $list.= '</nav>';  
    }     
    
    
    $list.= '</div>';
    wp_reset_query();
    return $list;
}
add_shortcode('snowreports', 'snowreports_shortcode');
5,097 Views

nginx server block configuration with cache – ubuntu 16.04

server {
    listen 80;
    listen [::]:80;

    root /var/www/yourdomain.com;
    index index.php index.html index.htm index.nginx-debian.html;

    server_name yourdomain.com www.yourdomain.com;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }    

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }

    etag on;
    expires 7d;
    if_modified_since before;

    gzip on;
    gzip_vary on;
    gzip_comp_level 6;
    gzip_types text/plain text/xml image/svg+xml # text/html in core already.
    application/rss+xml application/atom+xml application/xhtml+xml
    text/css application/json application/x-javascript
    application/font-otf application/font-ttf;

    location ~* \.(?:ttf|ttc|otf|eot|woff|woff2|css|js)$ {
      add_header Access-Control-Allow-Origin *;
    }

    location ~* \.php$ {
      fastcgi_param WP_NGINX_CONFIG done;
    }    
}
5,177 Views

Plugin update “Could not create directory” fix on ubuntu server

Login on ssh with root user & run command below

chown -R www-data:www-data /var/www/path-to-wp-directory

sudo find /var/www/path-to-wp-directory/ -type d -exec chmod 755 {} \;

sudo find /var/www/path-to-wp-directory/ -type f -exec chmod 644 {} \;

17,506 Views

Gravity form popup with bootstrap modal

function gf_popup_shortcode( $atts, $content = null  ) {

	extract( shortcode_atts( array(
		'title' => '',
		'id' => '',
		'text' => '',
	), $atts ) );

	return '
        <a class="gf-form-modal-trigger" href="" data-toggle="modal" data-target="#gf-popup-modal'.$id.'">'.$text.'</a>
        <div class="modal fade" id="gf-popup-modal'.$id.'" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel">'.$title.'</h4>
                    </div>
                    <div class="modal-body">
                        '.do_shortcode('[gravityform id="'.$id.'" title="false" description="false" ajax="true"]').'
                    </div>
                </div>
            </div>
        </div>
    ';
}	
add_shortcode('gf_popup', 'gf_popup_shortcode');
64,674 Views

Simple php server to server file download script

<?php
set_time_limit(0); //Unlimited max execution time
 
$path = 'archive.zip';
$url = 'http://google.com/archive.zip';
$newfname = $path;
echo 'Starting Download!<br>';
$file = fopen ($url, "rb");
if($file) {
	$newf = fopen ($newfname, "wb");
	if($newf)
		while(!feof($file)) {
			fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 );
			echo '1 MB File Chunk Written!<br>';
		}
}
if($file) {
	fclose($file);
}
if($newf) {
	fclose($newf);
}
echo 'Finished!';
?>
91,781 Views
Page 1 of 2612345...1020...Last »