spojetski
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: ‘max_user_connections’ troubleshootingwe’re on a sharing hosting. Thanks.
Forum: Developing with WordPress
In reply to: Widget cat’ exceptions ?Hello WP Provider,
My week-end is going well !
I am not certain this is what we were looking for, but my log shows “PHP Warning: Undefined array key “categories” in C:\Users\kevin\Local Sites\test-mobile\app\public\wp-content\themes\flex-mag\widgets\widget-catrow.php on line 128″
I actually tried the second option. The good news is with this method, the plugins doesnt disappear from the pannel and it shows something on the screen. But it selects a random (1) article and only one.
Have a great satursday night with your close ones !Forum: Developing with WordPress
In reply to: Widget cat’ exceptions ?Hello, i hope you are having a great week-end ! Unfortunately the more we dive into that topic, the more i realise i am not skilled enough to answer you despite your help and guidance. I don’t really know how to check if $categories is getting the correct category ID (wich is “all category”, in that case) considering (i believe) we used the same function structure and it was able to display all the categories before. I will look at debugging today and hopefully be able to give you some more informations.
I was thinking on top of my head earlier, rather than trying to identify the 4 articles that are actually labelled with a FEAT tag, could it be less of an hassle to tell the widget something along the lines of “get the latest 12 articles, but hide first 4 ?” no matter the tag, considering all the articles have the same tag and will therefore end up in that featured block. (Yes, it may seem simpler for me to say it like that, not knowing what it would really imply coding wise !)Forum: Developing with WordPress
In reply to: Widget cat’ exceptions ?This, i should not have gone by without finding myself … Shows i have not really gotten my head around that While – Endwhile function.
The good news, is it seems we are moving forward as we have no more error. On the other hand, the widget doesnt show any article. Im not giving up just yet :)))Edit: i have searche for a hint on the back-end, and the “Category Row Widget” has now disappeared from the widget setup page. It comes back after reverting the catrow.php file to the previous version.
Forum: Developing with WordPress
In reply to: Widget cat’ exceptions ?Hi. Thanks you once again.
It has proven difficult for us (yes, my wife tried to give me a hand tonight !) to understand exactly where we were meant to implement all this despite your clear step by step instruction, but i am not giving up !
I have once again provided the code (in full, that time !) with the additions and tweaks we have made in BOLD (i wasn’t too sure where to close that last } after “// … [rest of your widget display code] …” to be honest with you.
I am obviously not there yet, ending up with a parse error “Parse error: syntax error, unexpected token “endwhile” in C:\Users\kevin\Local Sites\test-mobile\app\public\wp-content\themes\flex-mag\widgets\widget-catrow.php on line 100“I am sorry if despite your clear explanation, i have yet to make it work !
<?php /** * Plugin Name: Category Row Widget */ function widget( $args, $instance ) { extract( $args ); add_action( 'widgets_init', 'mvp_catrow_load_widgets' ); function mvp_catrow_load_widgets() { register_widget( 'mvp_catrow_widget' ); } class mvp_catrow_widget extends WP_Widget { /** * Widget setup. */ function __construct() { /* Widget settings. */ $widget_ops = array( 'classname' => 'mvp_catrow_widget', 'description' => __('A widget that displays a list of posts from a category of your choice.', 'mvp-text') ); /* Widget control settings. */ $control_ops = array( 'width' => 250, 'height' => 350, 'id_base' => 'mvp_catrow_widget' ); /* Create the widget. */ parent::__construct( 'mvp_catrow_widget', __('Flex Mag: Category Row Widget', 'mvp-text'), $widget_ops, $control_ops ); } /** * How to display the widget on the screen. */ function widget( $args, $instance ) { extract( $args ); /* Our variables from the widget settings. */ global $post; $title = apply_filters('widget_title', $instance['title'] ); $categories = $instance['categories']; $showcat = $instance['showcat']; /* Before widget (defined by themes). */ echo $before_widget; /* Display the widget title if one was input (before and after defined by themes). */ if ( $title ) echo $before_title . $title . $after_title; ?> <div class="row-widget-wrap left relative"> <ul class="row-widget-list"> <?php // Identify Featured Articles $featured_posts = new WP_Query(array( 'tag' => 'feat', 'posts_per_page' => 4 )); $featured_ids = []; if ($featured_posts->have_posts()) { while ($featured_posts->have_posts()) { $featured_posts->the_post(); $featured_ids[] = get_the_ID(); } } wp_reset_postdata(); $recent = new WP_Query(array( 'cat' => $categories, 'posts_per_page' => 6, 'post__not_in' => $featured_ids )); ?> <li> <a href="<?php the_permalink(); ?>" rel="bookmark"> <?php if ( (function_exists('has_post_thumbnail')) && (has_post_thumbnail()) ) { ?> <div class="row-widget-img left relative"> <?php the_post_thumbnail('mvp-mid-thumb', array( 'class' => 'reg-img' )); ?> <?php the_post_thumbnail('mvp-small-thumb', array( 'class' => 'mob-img' )); ?> <?php $post_views = get_post_meta($post->ID, "post_views_count", true); if ( $post_views >= 1) { ?> <div class="feat-info-wrap"> <div class="feat-info-views"> <i class="fa fa-eye fa-2"></i> <span class="feat-info-text"><?php mvp_post_views(); ?></span> </div><!--feat-info-views--> <?php $disqus_id = get_option('mvp_disqus_id'); if ( ! $disqus_id ) { if (get_comments_number()==0) { } else { ?> <div class="feat-info-comm"> <i class="fa fa-comment"></i> <span class="feat-info-text"><?php comments_number( '0', '1', '%' ); ?></span> </div><!--feat-info-comm--> <?php } } ?> </div><!--feat-info-wrap--> <?php } ?> <?php if ( has_post_format( 'video' )) { ?> <div class="feat-vid-but"> <i class="fa fa-play fa-3"></i> </div><!--feat-vid-but--> <?php } ?> </div><!--row-widget-img--> <?php } ?> <div class="row-widget-text"> <?php if($showcat) { ?> <span class="side-list-cat"><?php $category = get_the_category(); echo esc_html( $category[0]->cat_name ); ?></span> <?php } ?> <p><?php the_title(); ?></p> </div><!--row-widget-text--> </a> </li> <?php endwhile; wp_reset_postdata(); ?> </ul> </div><!--row-widget-wrap--> <?php /* After widget (defined by themes). */ echo $after_widget; } /** * Update the widget settings. */ function update( $new_instance, $old_instance ) { $instance = $old_instance; /* Strip tags for title and name to remove HTML (important for text inputs). */ $instance['title'] = strip_tags( $new_instance['title'] ); $instance['categories'] = strip_tags( $new_instance['categories'] ); $instance['showcat'] = strip_tags( $new_instance['showcat'] ); return $instance; } function form( $instance ) { /* Set up some default widget settings. */ $defaults = array( 'title' => 'Title', 'showcat' => 'on' ); $instance = wp_parse_args( (array) $instance, $defaults ); ?> <!-- Widget Title: Text Input --> <p> <label for="<?php echo $this->get_field_id( 'title' ); ?>">Title:</label> <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:90%;" /> </p> <!-- Category --> <p> <label for="<?php echo $this->get_field_id('categories'); ?>">Select category:</label> <select id="<?php echo $this->get_field_id('categories'); ?>" name="<?php echo $this->get_field_name('categories'); ?>" style="width:100%;"> <option value='all' <?php if ('all' == $instance['categories']) echo 'selected="selected"'; ?>>All Categories</option> <?php $categories = get_categories('hide_empty=0&depth=1&type=post'); ?> <?php foreach($categories as $category) { ?> <option value='<?php echo $category->term_id; ?>' <?php if ($category->term_id == $instance['categories']) echo 'selected="selected"'; ?>><?php echo $category->cat_name; ?></option> <?php } ?> </select> </p> <!-- Show Categories --> <p> <label for="<?php echo $this->get_field_id( 'showcat' ); ?>">Show categories on posts:</label> <input type="checkbox" id="<?php echo $this->get_field_id( 'showcat' ); ?>" name="<?php echo $this->get_field_name( 'showcat' ); ?>" <?php checked( (bool) $instance['showcat'], true ); ?> /> </p> <?php } } } ?>Forum: Developing with WordPress
In reply to: Widget cat’ exceptions ?Sorry my clumsy finger somehow posted this too early. I’ve edited my previous answer with as many details i could give you.
This isn’t the mobile display but the desktop display on my clone local wordpress. This is the said widget and the said featured post block.
<?php /** * Plugin Name: Category Row Widget */ $featured_posts = new WP_Query(array( 'tag' => 'feat', 'posts_per_page' => 4 )); $featured_ids = []; if ($featured_posts->have_posts()) { while ($featured_posts->have_posts()) { $featured_posts->the_post(); $featured_ids[] = get_the_ID(); } } wp_reset_postdata(); add_action( 'widgets_init', 'mvp_catrow_load_widgets' ); function mvp_catrow_load_widgets() { register_widget( 'mvp_catrow_widget' ); } class mvp_catrow_widget extends WP_Widget { /** * Widget setup. */ function __construct() { /* Widget settings. */ $widget_ops = array( 'classname' => 'mvp_catrow_widget', 'description' => __('A widget that displays a list of posts from a category of your choice.', 'mvp-text') ); /* Widget control settings. */ $control_ops = array( 'width' => 250, 'height' => 350, 'id_base' => 'mvp_catrow_widget' ); /* Create the widget. */ parent::__construct( 'mvp_catrow_widget', __('Flex Mag: Category Row Widget', 'mvp-text'), $widget_ops, $control_ops ); } /** * How to display the widget on the screen. */ function widget( $args, $instance ) { extract( $args ); /* Our variables from the widget settings. */ global $post; $title = apply_filters('widget_title', $instance['title'] ); $categories = $instance['categories']; $showcat = $instance['showcat']; /* Before widget (defined by themes). */ echo $before_widget; /* Display the widget title if one was input (before and after defined by themes). */ if ( $title ) echo $before_title . $title . $after_title; ?> <div class="row-widget-wrap left relative"> <ul class="row-widget-list"> <?php $recent = new WP_Query(array( 'cat' => $categories, 'posts_per_page' => 6, 'post__not_in' => $featured_ids )); ?> <?php while($recent->have_posts()) : $recent->the_post(); ?> <li> <a href="<?php the_permalink(); ?>" rel="bookmark"> <?php if ( (function_exists('has_post_thumbnail')) && (has_post_thumbnail()) ) { ?> <div class="row-widget-img left relative"> <?php the_post_thumbnail('mvp-mid-thumb', array( 'class' => 'reg-img' )); ?> <?php the_post_thumbnail('mvp-small-thumb', array( 'class' => 'mob-img' )); ?> <?php $post_views = get_post_meta($post->ID, "post_views_count", true); if ( $post_views >= 1) { ?> <div class="feat-info-wrap"> <div class="feat-info-views"> <i class="fa fa-eye fa-2"></i> <span class="feat-info-text"><?php mvp_post_views(); ?></span> </div><!--feat-info-views--> <?php $disqus_id = get_option('mvp_disqus_id'); if ( ! $disqus_id ) { if (get_comments_number()==0) { } else { ?> <div class="feat-info-comm"> <i class="fa fa-comment"></i> <span class="feat-info-text"><?php comments_number( '0', '1', '%' ); ?></span> </div><!--feat-info-comm--> <?php } } ?> </div><!--feat-info-wrap--> <?php } ?> <?php if ( has_post_format( 'video' )) { ?> <div class="feat-vid-but"> <i class="fa fa-play fa-3"></i> </div><!--feat-vid-but--> <?php } ?> </div><!--row-widget-img--> <?php } ?> <div class="row-widget-text"> <?php if($showcat) { ?> <span class="side-list-cat"><?php $category = get_the_category(); echo esc_html( $category[0]->cat_name ); ?></span> <?php } ?> <p><?php the_title(); ?></p> </div><!--row-widget-text--> </a> </li> <?php endwhile; wp_reset_postdata(); ?> </ul> </div><!--row-widget-wrap-->Above is part of said file catrow.php
- This reply was modified 2 years, 4 months ago by spojetski.
Forum: Developing with WordPress
In reply to: Widget cat’ exceptions ?I can’t thank you enough for your help.
I am trying to get the hang of it, but i am unfortunately getting an error returned. “Warning: Undefined variable $featured_ids in C:\Users\kevin\Local Sites\test-mobile\app\public\wp-content\themes\flex-mag\widgets\widget-catrow.php on line 51“So, i believe i have followed the first few steps correctly … i believe.
I have implemented this $featured_posts function at the begining of my widget-catrow.php.:$featured_posts = new WP_Query(array( 'tag' => 'feat', 'posts_per_page' => 4 )); $featured_ids = []; if ($featured_posts->have_posts()) { while ($featured_posts->have_posts()) { $featured_posts->the_post(); $featured_ids[] = get_the_ID(); } } wp_reset_postdata();I have then edited my $recent function to :
<?php $recent = new WP_Query(array( 'cat' => $categories, 'posts_per_page' => 6, 'post__not_in' => $featured_ids )); ?>I was a bit confused as to how to implement the while($recent) function, perdon my lack of knowledge about PHP. I actually added it this way just after the $recent function:
<?php while($recent->have_posts()) : $recent->the_post(); ?>Then, the rest hasn’t been changed. I am trying to figure out what have i done wrong for the variable not to be defined. Learning everyday ! Thank you very much once again.
- This reply was modified 2 years, 4 months ago by spojetski.
Forum: Developing with WordPress
In reply to: Widget cat’ exceptions ?Thank you very much. I have a local copy of my website here so i can try and sort out. I have understand some of this will need to be tweaked and adjusted for us, but i am quite confused as to what exactly this will be replacing considering i’ll endup with multiple endwhile & reset_postdata in my widget-catrow.php.
Below is whole section to hopefully make this poor explanation sort of better !
<div class="row-widget-wrap left relative"> <ul class="row-widget-list"> <?php $recent = new WP_Query(array( 'cat' => $categories, 'posts_per_page' => 6 )); while($recent->have_posts()) : $recent->the_post(); ?> <li> <a href="<?php the_permalink(); ?>" rel="bookmark"> <?php if ( (function_exists('has_post_thumbnail')) && (has_post_thumbnail()) ) { ?> <div class="row-widget-img left relative"> <?php the_post_thumbnail('mvp-mid-thumb', array( 'class' => 'reg-img' )); ?> <?php the_post_thumbnail('mvp-small-thumb', array( 'class' => 'mob-img' )); ?> <?php $post_views = get_post_meta($post->ID, "post_views_count", true); if ( $post_views >= 1) { ?> <div class="feat-info-wrap"> <div class="feat-info-views"> <i class="fa fa-eye fa-2"></i> <span class="feat-info-text"><?php mvp_post_views(); ?></span> </div><!--feat-info-views--> <?php $disqus_id = get_option('mvp_disqus_id'); if ( ! $disqus_id ) { if (get_comments_number()==0) { } else { ?> <div class="feat-info-comm"> <i class="fa fa-comment"></i> <span class="feat-info-text"><?php comments_number( '0', '1', '%' ); ?></span> </div><!--feat-info-comm--> <?php } } ?> </div><!--feat-info-wrap--> <?php } ?> <?php if ( has_post_format( 'video' )) { ?> <div class="feat-vid-but"> <i class="fa fa-play fa-3"></i> </div><!--feat-vid-but--> <?php } ?> </div><!--row-widget-img--> <?php } ?> <div class="row-widget-text"> <?php if($showcat) { ?> <span class="side-list-cat"><?php $category = get_the_category(); echo esc_html( $category[0]->cat_name ); ?></span> <?php } ?> <p><?php the_title(); ?></p> </div><!--row-widget-text--> </a> </li> <?php endwhile; wp_reset_postdata(); ?> </ul> </div><!--row-widget-wrap-->Forum: Developing with WordPress
In reply to: Widget cat’ exceptions ?It always amaze me to see how some people are confortable with this while i’ve been struggling to keep up and improve my website for the last 7 years with my basic php/html/sql knowledge !
This may be above my actual skills and understanding but i’m willing to give it a go and understand it to make it work; otherwise i might have to get somebody !
“you’ll need to determine which articles are currently featured. This can usually be done based on categories, tags, or a custom field that marks an article as featured.” Just to make sure i understand this right – > All my articles ever created have gone through the “featured block” at some points, using the TAG: FEAT. You are telling me i should first let my website figure out that the last 4 articles with the Tag (i.e: ‘Category name’, in the code you kindly gave me shoud then be replace with tag name), “FEAT” are to be considered as non-existent for the CATEGORY ROW WIDGET we are working on ?]); $featured_ids = []; if ($featured_posts->have_posts()) { while ($featured_posts->have_posts()) { $featured_posts->the_post(); $featured_ids[] = get_the_ID(); } }I am trying to figure what this bit is doing. Thru these conditions, are we saying: “get the 4 (most recent ?) posts where category is “Featured”. If you find posts within the “Featured” Category, get their ID’s. Then, display the 6 (most recents ?) posts in the CATEGORY ROW WIDGET that have not been listed by their ID’s above.” ?
Once again, thank you for providing some help, fits your nickname !
- This reply was modified 2 years, 4 months ago by spojetski.
Forum: Developing with WordPress
In reply to: Widget cat’ exceptions ?Good Day WP Provider, thank you so much for stopping by and helping me as i wasn’t really sure where to start from.
I’ve carefully read your answer and i have 1 question:
“To do this, you’ll need the IDs of the articles in the Featured Block”. As we post about 1K+ articles a year, i am guessing the article ID we have to exclude will change everytime we post a new article ? Every article we post goes featured first.I am trying to work around this, if i understand correctly.
<?php $recent = new WP_Query(array( 'cat' => $categories, 'posts_per_page' => 6 )); while($recent->have_posts()) : $recent->the_post(); ?>Have a good day.
Kevin- This reply was modified 2 years, 4 months ago by spojetski.