Hello,
I’m trying to replicate category style top posts grid in main blog page. I have found that this piece of code is responsible. So I copied it inside the container to index page and it shows perfectly.
Except for one feature, it duplicates posts in the blog page. I wonder if anyone know how can I manually disable duplicate posts in index.php in addition to this code.
<?php td_api_category_template::_helper_show_category_template() ?>
<?php td_api_category_top_posts_style::_helper_show_category_top_posts_style() ?>
Extra information:
Wordpress 4.21
Newsmag 1.7.1 (Thank you for the update)
We don’t use Visual Composer, tagdiv speed booster or any other plugin bundled with theme.
Why? Because I have tried every version but our CPU use still goes crazy and site is non responsive with these plugins enabled. I have waited for a month for updates, got them, nothing changed. I tried nearly every plugin combination, including disabling every other plugin and only enabling these plugins. It’s impossible, page load time goes to 45 seconds to no response. In my previous post I explained that this happens with hundreds of concurrent online users, so normal blogs need not be alarmed. Also it just doesn’t load normally in page edit screen (Checked for that option it’s correctly set) it gets loaded then dissapears out of page. Tried with different browsers too. But solving is not important anymore with high admin ajax use on server it’s done for me.
I like the themes quality coding, speed, style and options. But with in this situation I have to make this simple change because I can’t use VC for this. I would very much love to see some more styling options included for blog and posts section of theme options, instead of relying on VC.
So if you can point me in right direction I want to make this change works.
Best Regards,
Hi,
@aleister – It’s not enough, the theme also comes with a function inside function.php which adds an offset for the categories on which the BigGrid is set – http://screencast.com/t/LGBxhzqx
You have to add a similar function which sets an offset for blog page, ex. – http://pastebin.com/zmBfyXAb
We may release a light modified version of Visual Composer in the future, but it may take some time and i cannot promise anything yet because we’re still in the testing and looking for solutions phase and i’m not sure if it will work.
Did you tried with older/newer versions of VC? (sorry if i don’t remember, we have a lot of clients and it’s hard to remember particular cases).
Thank you, Emil G.
Yep I tried older versions too, your staff kindly provided older versions. Yet it only seemed to work for a shot time then I realised it was a momentary thing.
And the code you provided worked like charm. You can see it at https://www.technopat.net It’s without visual composer or any of the plugins provided, just Newsmag.
Thank you,
-
This reply was modified 11 years by
aleister.
Hi,
Nice job 🙂
I can provide the latest version of VC (4.5), it just came out, if you want to test it please send an email at contact@tagdiv.com and include a paste to this conversation. We didn’t tested it yet so i cannot confirm that it will solve anything.
I also created a ticket on wpbakery for the blank screen which appears on newer versions of VC for some of our clients but the things move slow and i’m not sure if they’ll come with a solution. It may be related to what you’re experiencing on your side.
Thank you, Emil G.
Hi,
Unfortunately it’s not easily doable, you could set a tag filter but then you have to pass the exact posts which are excluded from the loop, on it’s actual form it uses an offset of 5 posts but it only work if the filters are identical for grid and blog loop. My advice is to hire a professional to modify the code for you, the grid was built for the category page, other issues or errors may appear if it’s used somewhere else without applying the necessary adjustments on the code.
Thank you, Emil G.
Wow…. You know … That is really clever.
Tagdiv could almost make a new homepage version which is basically, a new category page, and add options in the theme panel … Just like managing, say any category is done now, but with all the latest posts.
I am going to try doing what you did here, as vc kills our system a s of 1.7, while 1.6 can spike a little bit on high traffic site with php going to yellow from green over and over.
Going to give this method a whirl…!
-
This reply was modified 11 years by
simchris.
Hi,
Please try to make this changes: http://screencast.com/t/Qv6xgvhr and let me know how it goes.
Thanks
This is the error I get:
Parse error: syntax error, unexpected 'and' (T_LOGICAL_AND) in /home/sitename/public_html/wp-content/themes/Newsmag/includes/wp_booster/td_wp_booster_functions.php on line 1656
and the code I use is
/* —————————————————————————-
* modify the main query for category pages
*/
add_action(‘pre_get_posts’, ‘td_modify_main_query_for_category_page’);
function td_modify_main_query_for_category_page($query) {
//checking for category page and main query
if(!is_admin() and is_category() and $query->is_main_query()) and (is_front_page() and is_home() )){
// get the category object – with or without permalinks
if (empty($query->query_vars[‘cat’])) {
td_global::$current_category_obj = get_category_by_path(get_query_var(‘category_name’), false); // when we have permalinks, we have to get the category object like this.
} else {
td_global::$current_category_obj = get_category($query->query_vars[‘cat’]);
}
// we are on a category page with an ID that doesn’t exists – wp will show a 404 and we do nothing
if (is_null(td_global::$current_category_obj)) {
return;
}
//get the number of page where on
$paged = get_query_var(‘paged’);
//get the filter_by` URL($_GET) variable
$filter_by = get_query_var('filter_by');
//get the limit of posts on the category page
$limit = get_option('posts_per_page');
//echo $filter_by;
switch ($filter_by) {
case 'featured':
//get the category object
$query->set('category_name', td_global::$current_category_obj->slug);
$query->set('cat', get_cat_ID(TD_FEATURED_CAT)); //add the fetured cat
break;
case 'popular':
$query->set('meta_key', td_page_views::$post_view_counter_key);
$query->set('orderby', 'meta_value_num');
$query->set('order', 'DESC');
break;
case 'popular7':
$query->set('meta_key', td_page_views::$post_view_counter_7_day_total);
$query->set('orderby', 'meta_value_num');
$query->set('order', 'DESC');
break;
case 'review_high':
$query->set('meta_key', td_review::$td_review_key);
$query->set('orderby', 'meta_value_num');
$query->set('order', 'DESC');
break;
case 'random_posts':
$query->set('orderby', 'rand');
break;
}//end switch
// how many posts are we showing in the big grid for this category
$offset = 5;
// offset + custom pagination - if we have offset, WordPress overwrites the pagination and works with offset + limit
if(empty($query->is_feed)) {
if ( ! empty( $offset ) and $paged > 1 ) {
$query->set( 'offset', $offset + ( ( $paged - 1 ) * $limit ) );
} else {
$query->set( 'offset', $offset );
}
}
//print_r($query);
}//end if main query
} `
it was
/* ----------------------------------------------------------------------------
* modify the main query for category pages
*/
add_action('pre_get_posts', 'td_modify_main_query_for_category_page');
function td_modify_main_query_for_category_page($query) {
//checking for category page and main query
if(!is_admin() and is_category() and $query->is_main_query()) {
// get the category object - with or without permalinks
if (empty($query->query_vars['cat'])) {
td_global::$current_category_obj = get_category_by_path(get_query_var('category_name'), false); // when we have permalinks, we have to get the category object like this.
} else {
td_global::$current_category_obj = get_category($query->query_vars['cat']);
}
// we are on a category page with an ID that doesn't exists - wp will show a 404 and we do nothing
if (is_null(td_global::$current_category_obj)) {
return;
}
//get the number of page where on
$paged = get_query_var('paged');
//get the filter_by` URL($_GET) variable
$filter_by = get_query_var('filter_by');
//get the limit of posts on the category page
$limit = get_option('posts_per_page');
//echo $filter_by;
switch ($filter_by) {
case 'featured':
//get the category object
$query->set('category_name', td_global::$current_category_obj->slug);
$query->set('cat', get_cat_ID(TD_FEATURED_CAT)); //add the fetured cat
break;
case 'popular':
$query->set('meta_key', td_page_views::$post_view_counter_key);
$query->set('orderby', 'meta_value_num');
$query->set('order', 'DESC');
break;
case 'popular7':
$query->set('meta_key', td_page_views::$post_view_counter_7_day_total);
$query->set('orderby', 'meta_value_num');
$query->set('order', 'DESC');
break;
case 'review_high':
$query->set('meta_key', td_review::$td_review_key);
$query->set('orderby', 'meta_value_num');
$query->set('order', 'DESC');
break;
case 'random_posts':
$query->set('orderby', 'rand');
break;
}//end switch
// how many posts are we showing in the big grid for this category
$offset = td_api_category_top_posts_style::_helper_get_posts_shown_in_the_loop();
// offset + custom pagination - if we have offset, WordPress overwrites the pagination and works with offset + limit
if(empty($query->is_feed)) {
if ( ! empty( $offset ) and $paged > 1 ) {
$query->set( 'offset', $offset + ( ( $paged - 1 ) * $limit ) );
} else {
$query->set( 'offset', $offset );
}
}
//print_r($query);
}//end if main query
}`
I believe this part is the error
<code> // how many posts are we showing in the big grid for this category
$offset = td_api_category_top_posts_style::_helper_get_posts_shown_in_the_loop();
Any directions would be very welcome,
Site is http://www.technopat.net
Thank you
Hi,
I find the code you’ve pasted here very difficult to read so could you please use http://pastebin.com/ to send the one you use so I can check it. Please let me know or contact us via email at contact@tagdiv.com and send the whole file.
Also try to use this function: http://pastebin.com/ACZS1kde in addition to the one present in the theme.
Hope this helps!
Thanks
Hi,
Sorry for messy code, tried code tag but will use pastebin from now on.
I copy pasted the part you gave and recieved a new error: IMGur Error Image
And here is how I pasted it to wp_booster_functions, the entire code: http://pastebin.com/v9XFKkV8
Hi,
No problem. Use this function: http://pastebin.com/N90mXTtX I have tested it and it should work fine now.
You had this happening because this has been updated in the latest theme version, please consider that I can’t guarantee it will also work in next or future updates and this is just a workaround as it hasn’t been designed to work this way so I advise you to turn to a developer to find another implementation for this it it happens again.
Thanks for the message and for understanding!