Forum Replies Created

Viewing 15 replies - 91 through 105 (of 152 total)
  • Plugin Author piccart

    (@piccart)

    hi there!

    you have to put it in your theme’s functions.php, sorry if I haven’t specified it.
    in any case, as a general must-do rule, remember to don’t ever edit wordpress core files. basically you should never edit anything outside of the themes folder. ??

    then when you put the function in the correct position, this is what it’ll do
    – every time you load a page where the widget is displayed, it will check if there is a value passed from the url for the var countrycode
    – if there is any, it will ensure that you have set a taxonomy name in the widget options
    – if everything is fine it will set the query to filter by that term slug

    – if you haven’t set a taxonomy name the filter will be skipped and the widget will display as if the function didn’t exist
    – if there isn’t a countrycode in the url, it will be skipped as well
    – if you set a taxonomy name but it is incorrect, the query won’t find any post matching
    – if the provided term slug doesn’t exists or it’s incorrect, simply the query won’t find any post matching and will be empty (the widget then output “no matches found”)

    in any case, I haven’t tested the function, so please let me know if it doesn’t work after you put it in the theme’s functions.php
    by the way, if you refresh the page a few times it should pick up the new filter straight away. ??

    cheers

    Plugin Author piccart

    (@piccart)

    Hi there!

    I’m sorry if I confused you, I’ll try to be more clear.

    the point is all about what will you pass with the url. will it be the term slug or term id?

    I assume that “FR” is the “term name”, and the “term slug” is probably “fr”. Am I correct?

    if you go to your taxonomy admin page, where you have the list of all your country terms, you will notice that there is a column called “slug”.
    that is the value you will have to pass within the url if you want to use the SECOND FUNCTION.

    instead, if you click to edit one of your terms in admin, and then look the url of the page, you will see that at one point there is
    tag_ID=
    the number after that = is the ID of the term you are viewing.
    if you pass this value within your url, then you’d use the FIRST FUNCTION.

    the important thing is that you shouldn’t pass the “Term Name” in any case, because it is not a valid parameter for the query.

    let me know if you still have doubts!

    p.s. with both those functions, you can set any term in the widget option, and the filter will overwrite it and put the one passed by the url.

    Plugin Author piccart

    (@piccart)

    Hello Wordnow!

    many thanks for your appreciation and postive feedback!
    Please don’t forget to leave a quick review to the plugin if you enjoy it. it is really important for me. ??

    What you need to do can be easily achieved using one of the plugin’s filters.
    the quickest way would be if your url pass the Term ID rather than the Term Slug.
    if you can set it up in that way, you can just add this function to your functions.php

    /**
     * FILTER POSTS BASED ON TERM PASSED BY THE URL
     *
     * the variable MUST be the term ID
     * the filter assumes that the correct Taxonomy is already set within the widget options
     *
     * if no variable is passed, the filter will simply return the same instance
     *
     */
    add_filter( 'pbytax_prepare_instance', 'pbytax_filter_by_url_var_term', 11, 3 );
    
    function pbytax_filter_by_url_var_term( $new_instance, $instance, $widget_num ){
    	// get the variable from the url
    	$url_term = $_GET['countrycode'];
    
    	// if we got something, set this value as filter_term for the widget
    	if ( isset($url_term) && !empty($url_term) ){
    
    		$new_instance['filter_term'] = intval($url_term);
    
    	}
    
    	// return the instance
    	return $new_instance;
    
    }

    but if for you is important to have the term slug in the url, then we have to hook to the $args and change them to accept a slug rather than the expected ID.
    it’s still pretty easy though, and you just have to add this function instead:

    /**
     * FILTER POSTS BASED ON TERM PASSED BY THE URL
     *
     * the variable MUST be the slug of the term
     * the filter assumes that the correct Taxonomy is already set within the widget options
     *
     * if no variable is passed, or no tax_query was set from the widget options,
     	the filter will simply return the same $args
     *
     */
    
    add_filter( 'pbytax_query_args', 'pbytax_filter_by_url_var_term', 11, 3 );
    
    function pbytax_filter_by_url_var_term( $pbytax_args, $instance, $widget_num ){
    	// get the variable from the url
    	$url_term = $_GET['countrycode'];
    
    		// if we got something, ensure that we also have a tax_query set into our query args
    		if ( isset($url_term) && !empty($url_term) && $pbytax_args['tax_query'] ){
    
    			// set the field to be "slug" and the terms to be the string passed by the url
    			$pbytax_args['tax_query']['field'] = "slug";
    			$pbytax_args['tax_query']['terms'] = $url_term;
    
    		}
    
    	//return the args
    	return $pbytax_args;
    
    }

    let me know if it works or if you have doubts!
    cheers!

    Plugin Author piccart

    (@piccart)

    I’m glad it solved your problems!

    have a nice day! ??

    Plugin Author piccart

    (@piccart)

    Hello Sundbom!
    thanks for your compliments. ??

    yes, there is a smart and easy way to achieve what you need. ??
    you just have to add this function to your theme’s functions.php

    /**
     * FILTER WP-LIST-PAGES-BY-CUSTOM-TAX TO DISPLAY ONLY LAST WEEK POSTS
     *
     * this will hook to any widget
     * if you want to apply only to a specific widget instance, check its number on the widget admin
     * and then add a conditional in this function to apply only if $widget_num is equal to that number
     *
     * Author: Andrea Piccart
     * Author URI: https://bespokewebdeveloper.com
     * Plugin URI: https://www.ads-software.com/plugins/wp-list-pages-by-custom-taxonomy/
     *
     */
    add_filter( 'pbytax_query_args', 'pbytax_display_last_week_posts', 10, 3);
    
    function pbytax_display_last_week_posts( $pbytax_args, $instance, $widget_num ){
    	// add the parameter to limit the post to the last week
    	$pbytax_args['date_query'] = array(
            							array(
            	    						'after' => '1 week ago'
            							)
        							);
    	// return the customized args
    	return $pbytax_args;
    }

    this will filter my plugin’s query args and limit the results to the last week.

    though, you could also limit this behaviour only to a specific widget, and target only one specific widget number (as explained in the function’s top comments).

    in any case I am taking note of this as could be an additional functionality for the future updates. ??

    Thanks for the suggestion and please take a minute to review the plugin, because it’s very important to me. ??

    cheers!

    Plugin Author piccart

    (@piccart)

    hi there!

    glad you’ve managed to achieve what you need, and thanks again for your words! ??

    cheers!

    Plugin Author piccart

    (@piccart)

    Hello!
    thanks for your great feedback and for the rating!! it’s really appreciated! ??

    since version 1.4 the above code must be tweaked because to avoid overriding the $post variable, I’m now using a custom variable for the retrieved posts object.

    so whenever you want to get something from the currently looped post, you must use $pbytax_post instead of $post.
    by instance in your code you would put:
    $pbytax_post->ID

    then it should work just fine.
    cheers!

    Plugin Author piccart

    (@piccart)

    Hi there!

    I’m glad that you’ve been able to achieve what you needed!

    don’t forget to rate my plugin if you have a spare couple of minutes. ??

    many thanks!

    Plugin Author piccart

    (@piccart)

    Hello!

    to achieve what you need, you can add this little filter which will modify the widget’s query and force it to retrieve only posts with all the selected terms:

    /**
     * RETRIEVE ONLY POSTS WHICH ARE IN BOTH SELECTED TERMS
     *
     * @hook	'pbytax_query_args'		/pages-by-custom-tax.php
     * filters the query args for the widget PbyTax
     * changes the "operator" parameter of the query and set it to AND
     *
     */
    add_filter ('pbytax_query_args', 'bwd_change_tax_query_relation', 10, 3);
    function bwd_change_tax_query_relation( $pbytax_args, $instance, $widget_num ) {
    	// apply only if tax_query is actually set
    	if ( $pbytax_args['tax_query'] ){ 	// you could apply the filter only to a specific widget instance if you change this line to this:
    										// if ( $pbytax_args['tax_query'] && $widget_num == 2){
    
    		// set the operator to be AND, this will return only post having both of the selected terms
    		$pbytax_args['tax_query'][0]['operator'] = 'AND';
    
    	}	
    
    	// return the filtered args
    	return $pbytax_args;
    }

    you have to place this code within your theme’s functions.php file.
    you can edit the file using a program, or from your host admin panel, or from the wp admin section in Appearance>Editor and then selecting functions.php file

    as explained by the comments within the code, you could set the filter to target only one specific widget number, rather than applying to any widget instance.

    let me know how it goes!
    cheers!

    Plugin Author piccart

    (@piccart)

    Hello Ansesis,

    I’m afraid that you are probably misunderstunding the meaning of “taxonomy”.

    taxonomy is the general name for things like “categories” and “tags”.
    we use the general name because you can have a lot of custom taxonomies in addition to the default post’s categories and tags. indeed your current wp setup has a bunch of other taxonomies, and nav_menu is one of them.

    so if you select something as “taxonomy” it will tell the plugin to filter and display only pages which are within that taxonomy. as per your selection it would display only posts which have any term from the taxonomy “nav_menu”. which is not what you’re looking for.

    you should just select “any” for taxonomy and term, and then you have to select the checkbox where it says to “Display only titles in a dropdown selector”.

    let me know if you still have doubts/problems.
    cheers!

    Plugin Author piccart

    (@piccart)

    Hi Leah!

    I just published the new version 1.4.1
    as promised, it includes the option to “exclude current post” from the list. ??

    Don’t forget to rate the plugin if you have a minute! ??
    thanks!

    Plugin Author piccart

    (@piccart)

    Hello Leah,
    many thanks for your kind words!
    I’m pleased that my plugin has been useful for you. ??

    regarding your feature request, it definitely makes sense and it will be easy to implement it.
    I’m going to publish a new version very soon (wp 4.5 just came out), and I’ll make sure to include this feature in the update.

    Bear with me, it’ll be very soon, I promise! ??

    I’ll let you know when is out
    cheers!

    Plugin Author piccart

    (@piccart)

    Hello Isla!
    thanks for your words and compliments!

    the only way for achieving that, is to create a customized version of the template file which displays the widget.

    you should create a duplicate of this file
    /plugins/wp-list-pages-by-custom-taxonomy/templates/pbytax_template.php

    and then place the duplicate into your theme main folder.
    then open this duplicate and look for this bit of code:

    <span class="postbytax-title-wrap"><a class="pbytax-post-title" href="<?php echo esc_url( get_permalink( $pbytax_post->ID ) ); ?>" title="<?php echo esc_attr( $pbytax_post->post_title ); ?>"><?php echo $pbytax_post->post_title ?></a></span>
                                    <?php if ($display_date=="yes"){
                                        ?>
                                        <span class="pbytax-date"><?php echo get_the_date( 'd-m-Y', $pbytax_post->ID ); ?></span>
                                    <?php } ?>

    you have to invert the title and date bits, so it would look like this:

    <?php if ($display_date=="yes"){
                                        ?>
                                        <span class="pbytax-date"><?php echo get_the_date( 'd-m-Y', $pbytax_post->ID ); ?></span>
                                    <?php } ?>
    <span class="postbytax-title-wrap"><a class="pbytax-post-title" href="<?php echo esc_url( get_permalink( $pbytax_post->ID ) ); ?>" title="<?php echo esc_attr( $pbytax_post->post_title ); ?>"><?php echo $pbytax_post->post_title ?></a></span>

    last thing to do is to add a css tweak because by default the date is aligned on rightside.
    place this in your style.css or in a custom css editor of your template options, if you have any

    ul.pbytax-list li.pbytax-item .pbytax-date {
       float:left;
    }

    have a try and let me know if you have doubts or problems
    cheers!

    Plugin Author piccart

    (@piccart)

    Hi Willem,
    I’m glad it’s been easy for you to update it. ??

    I guess that you could search for a Poll plugin. so the thing would be to make a widget in which you ask a question (“How would you rate my Blog?”), and put the rating values as possible answers.

    there are a lot of polls plugins out there, but I haven’t used any of them so I am sorry but I cannot suggest one in particular..

    I hope I’ve been of some help.
    cheers!

    Plugin Author piccart

    (@piccart)

    hello!

    since version 1.4.0, the code within the template file is a bit changed, so the variable $post is now

    $pbytax_post

    therefore, in all the code samples above, you should substitute $post with $pbytax_post every time you find it.

    cheers!

Viewing 15 replies - 91 through 105 (of 152 total)