Sauter la navigation

[Résolu] View that shows all articles belong to alphabetical taxanomie view

This support ticket is created Il y a 5 années et 6 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Auteur
Publications
#1274309

Hi,
I have a problem with a view on my site. It has some nested views and in the nested view (that displays tags/taxonomies in alphabetical order a-z), if you click on a letter (for example a) it shows all words/taxanomies for that letter. But if I click on tht word, it shows all articles that exists to that word. I have to implement another view that shows an overview of all articles which belong to that aphabetical word. I don't know, how to realize that. Could you please take a look?
Thanks
Thorsten

#1274549

Hi Thorsten,

Thank you for contacting us and I'd be happy to assist.

There are a couple of ways, you can restrict the view to show only posts, starting from a specific alphabetical letter.

1. You can use the filter "wpv_filter_query" to include a query filter, as explained by Minesh, in this reply:
https://toolset.com/forums/topic/filtering-artist-by-selecting-the-first-letter-of-the-title/#post-602852

OR

2. You can add a new custom field, for example, "Starting Letter" to your articles post type and either manually or programmatically add the starting letter from the title into it.

To programmatically update the value in a custom field, you can use the "save_post" hook, as explained in this guide:
https://toolset.com/documentation/customizing-sites-using-php/updating-types-fields-using-php/

As a result, you'll be able to filter the posts in the view, based on the value from this new custom field.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1274563

Hi Waqar,

thanks for your suggestion! However, I think, the problem is quite more difficult (at least for me). For that reason I made 2 Videos and some screenshots to show you, what I try to achieve. Because the upload size and movies can't be uploaded here, I uploaded them to: lien caché
In the first Video (Stichwörter View_1.mp4) you see, what that is the problem. If you click on one of the alphabetical letters, all words appear for that letter (which is correct). But if I click on one of these words, you see that the article will be displayed (which it shouldn't) and the article also displays more than one time (which is also wrong). There has to be another view after clicking on the word with all articles which belong to the word (like you can see in the second video "Stichwörter View_1.mp4 at 00:13). I also attached screenshots in the zip. The picture "Stichwörter_Alphabetical_FirstView.jpg" is the view which displays the alphabetical letters. The second view "Stichwörter_Alphabetical_SecondView.jpg" shows the view, which displays the words after clicking on the alphabetical letters. Minesh did them kindly and also did the custom Code for the alphabetical letters (I know it is outside your support). So how can I get in the view for listing articles which belong to the words?
Also do you know, how to modify the code to also display not only the alphabetical letters, but also "words", which begin with a number? So right now it displays the letters from A-Z but additional I would like to display 0-9 for words which begin with a number.
Thanks
Thorsten

#1275415

Hi Thorsten,

Thanks for writing back and for sharing these details.

To better understand how these views and the custom code is set up and working, I'll need a clone/snapshot of your website.

This will allow me to troubleshoot and suggest the best way to adjust these views accordingly.

Here is a guide on how to share a clone/snapshot of the website:
https://toolset.com/faq/provide-supporters-copy-site/

Note: Your next reply will be private.

regards,
Waqar

#1276483

Hi Thorsten,

Thank you for waiting and for sharing the snapshot of the website.

Initially, I had some difficulty getting access to your website's admin area, due to the coming soon plugin, but I eventually figured out how to access it using the access key, from the plugin's settings from the snapshot.

Unfortunately, your website's snapshot showed blank pages on the front-end when deployed on my own server, and I was restricted to use your actual website's admin area, to see how everything was set up.

The pages which are shown, when a tag title is clicked after selecting an "Alphabet" are the archive pages for each "Tag" term:

Examples:
lien caché
lien caché
lien caché

Currently, these pages are using the default template "Inhalts-Template" ( lien caché ), from the Oxygen builder, but you can create a new "WordPress Archive" view for these post tag archives, from WP Admin -> Toolset -> WordPress Archives.

Here is a detailed guide on the topic:
https://toolset.com/documentation/getting-started-with-toolset/customize-post-archives/designing-an-archive-without-any-page-builder/

Another alternative is to create a new view to show the "articles" post, but include a query filter to show only those which have a tag attached, whose slug is passed through a URL parameter.
Example screenshot: lien caché

You can then add this new view into a new page, for example, "Articles by Tag" ( e.g. lien caché ).

In the content template of your view "Stichwoerter Alphabetical Second View", you can then replace:


<div>[wpv-taxonomy-link]</div>

With:


<div><a href="<em><u>lien caché</u></em>;">[wpv-taxonomy-title]</a></div>

Feel free to adjust the title and slug of this new page, as needed.

Additionally, to make the filtering of this view ( "Stichwoerter Alphabetical Second View" ) also work titles starting with 0-9, you can update the custom code to:


add_filter( 'wpv_filter_taxonomy_query', 'func_filter_taxview_by_char', 99, 4 );
function func_filter_taxview_by_char($tax_query_settings, $view_settings, $view_id){

	if($view_id == 1591 and isset($_GET['terms-filter']) and $_GET['terms-filter']!=""){

		// get the first character from the URL parameter "terms-filter"
		$firstCharacterTerm = strtolower(mb_substr($_GET['terms-filter'], 0, 1));

		// Get all the tags
		$res =  get_terms( 'post_tag', 'orderby=name&hide_empty=0' );
		
		$ids = array();
		
		foreach($res as $k=>$v):
			// get the first character from the name of the current tag in the loop
			$firstCharacterItem = strtolower(mb_substr($v->name, 0, 1));

			// only store the tag ID if the first character from the name matches the one from the URL parameter "terms-filter"
			if($firstCharacterItem == $firstCharacterTerm) {
				$ids[] = $v->term_id;
			}
		
		endforeach;

		$tax_query_settings['include'] =  	join(",",$ids);
	}
	else if($view_id == 1591 and !isset($_GET['terms-filter'])){
		// if no URL parameter "terms-filter" is set, don't show any tag
		$tax_query_settings['name__like'] =  "00000";

	}

	return $tax_query_settings;
}

Note: To include the options for 0-9, you'll also need to add each number as a seperate term in the custom taxonomy "Alphabetical Taxanomies", since currently there are only terms for A-Z.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1277239

Hi Waqar,
thanks you very much for your solutions and help. I took the alternative with the new articles view with the get parameter and that worked. 🙂
Regarding the 0-9 topic. Is it also possible not to show the numbers 0-9 individually ([0], [1], [2] etc.) but in this way: [0-9]? So that the user clicks on [0-9] and than it shows all Words/Tags that begin with a number (for example "10 Gebote")?
Regarding your problems. Yes, I think the Coming soon plugin is the problem. You have to use the link lien caché and also you could deactivate the coming soon plugin on your local installation.

Thanks again
Thorsten

#1277499

Hi Thorsten,

Thanks for the update and glad my message helped.

If you'd like to handle all titles starting with any number (0-9) as one case, rather than individually, you can add a new single entry [0-9] in your "Alphabetical Taxanomies" and make sure its slug is any number ( 0-9 ) and update the custom code slightly:


add_filter( 'wpv_filter_taxonomy_query', 'func_filter_taxview_by_char', 99, 4 );
function func_filter_taxview_by_char($tax_query_settings, $view_settings, $view_id){

	if($view_id == 1591 and isset($_GET['terms-filter']) and $_GET['terms-filter']!=""){

		// get the first character from the URL parameter "terms-filter"
		$firstCharacterTerm = mb_substr($_GET['terms-filter'], 0, 1);

		if (is_numeric($_GET['terms-filter'])) {
			$isNumericQuery = true;
		}
		else
		{
			$isNumericQuery = false;
			// convert the first character from the URL parameter "terms-filter" to lowercase
			$firstCharacterTerm = strtolower($firstCharacterTerm);
		}

		// Get all the tags
		$res =  get_terms( 'post_tag', 'orderby=name&hide_empty=0' );
		
		$ids = array();
		
		foreach($res as $k=>$v):

			// get the first character from the name of the current tag in the loop
			$firstCharacterItem = mb_substr($v->name, 0, 1);

			if ($isNumericQuery) {
				// only store the tag ID if the first character from the name is numeric
				if (is_numeric($firstCharacterItem)) {
					$ids[] = $v->term_id;
				}
			}
			else
			{
				// convert the first character from the name of the current tag in the loop to lowercase
				$firstCharacterItem = strtolower($firstCharacterItem);

				// only store the tag ID if the first character from the name matches the one from the URL parameter "terms-filter"
				if($firstCharacterItem == $firstCharacterTerm) {
					$ids[] = $v->term_id;
				}
			}
					
		endforeach;

		$tax_query_settings['include'] =  	join(",",$ids);
	}
	else if($view_id == 1591 and !isset($_GET['terms-filter'])){
		// if no URL parameter "terms-filter" is set, don't show any tag
		$tax_query_settings['name__like'] =  "00000";

	}

	return $tax_query_settings;
}

As a result, when the value of the URL parameter "terms-filter" will be numeric, it will show all tags starting with numbers (0-9) and if not, it will show the ones starting with the selected Alphabetical letter.

Important note: As much as we would like to help, 1-1 custom code assistance is beyond the scope of support that we can provide ( ref: https://toolset.com/toolset-support-policy/ ).

We do our best to guide in the right direction, whenever possible, but for more personalized assistance around code customizations, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

regards,
Waqar

#1278317

Thank you so much Waqar for helping me out to solve my issues though I know that the custom code is not in your support policy. All works fine now. I only hat to modify the code for the 0-9 problem. Instead of using:

 /* if (is_numeric($_GET['terms-filter'])) {
            $isNumericQuery = true;
        }
        else
        {
            $isNumericQuery = false;
            // convert the first character from the URL parameter "terms-filter" to lowercase
            $firstCharacterTerm = strtolower($firstCharacterTerm);
        }

I modified the code to:

if ($firstCharacterTerm[0] === "0") {
        $isNumericQuery = true;
      } else {
        $isNumericQuery = false;
            // convert the first character from the URL parameter "terms-filter" to lowercase
            $firstCharacterTerm = strtolower($firstCharacterTerm);
      }

because if he checked the term in the URL get parameter, he always recognized it as a string. Now it works as expected. 🙂

Thanks again
Thorsten