- This topic has 17 replies, 3 voices, and was last updated 4 years, 7 months ago by Tom.
-
AuthorPosts
-
September 19, 2019 at 4:21 am #1013395webcréateur
We created a custom taxonomy called “issue“. In this taxonomy “issue”, we create terms like “Issues by date”. For example, “Issue from 19.09.2019”. We will be able to know in which issue the post we publish was published. The post are from a weekly newspaper, that’s the reason why we need to know in which issue the post was published.
We also have to display the issues from the custom taxonomy “issue” and a specific category in a new archive template. For that, I created a file taxonomy-issue.php and uploaded to child theme folder. Now I am trying to display all posts from “Issue from 19.09.2019” sorted by category “Economy” with WP Show Posts Pro with the function like:
<?php if ( function_exists( 'wpsp_display' ) ) wpsp_display( 38803 ); ?>
The problem is that we cannot choose a taxonomy “economy” and a term from custom taxonomy “Issue from 19.09.2019” to display only posts from the issue “Issue from 19.09.2019” and the category “economy …
I cannot see the forest for the trees. Could please give me hint how to solve this. Is this even possible with WP Show Post Pro?
September 19, 2019 at 5:07 am #1013427webcréateurIt is possible to display WordPress filter functions by URL manipulation, like:
https://example.org/issue/issue-from-19-09-2019/?category_name=economy
or
https://example.org/?category_name=economy&issue=issue-from-19-09-2019
or
https://example.org/?category_name=wordpress&tag=pluginsAny change to filter like this in WP Show Posts Pro? Or as a function?
Thank you.
September 19, 2019 at 5:12 am #1013428mikeb82Bill Erickson’s Display Posts plugin has a lot of options.
https://wordpress.org/plugins/display-posts-shortcode/September 19, 2019 at 8:59 am #1013710webcréateur@mikeb82 THX
But we are working WP Show Posts Pro. Would be nice to filter like this in WP Show Posts Pro, too?
https://example.org/?category_name=wordpress&tag=pluginsSeptember 19, 2019 at 9:09 am #1013721webcréateurTherefore, in WP Show Post it should be possible to select 2 times in a taxonomy?
https://prnt.sc/p8bgp0September 19, 2019 at 10:59 am #1013864TomLead DeveloperLead DeveloperAs of right now, it’s not possible to specify multiple taxonomies, unfortunately.
What you can try is adding
$settings
to this line: https://github.com/tomusborne/wp-show-posts/blob/1.1.3/wp-show-posts.php#L383So it looks like this: https://github.com/tomusborne/wp-show-posts/blob/release/1.2/wp-show-posts.php#L391
That will be in WPSP 1.2.
Then you can try something like this:
add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) { if ( 123 === $settings['list_id'] ) { $tax_args = array( 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'issue' 'field' => 'term_id', 'terms' => 100 ), array( 'taxonomy' => 'acme_labels', 'field' => 'term_id', 'terms' => 200 ) ) ); $args = array_merge( $args, $tax_args ); } return $args; }, 10, 2 );
This article should help when it comes to actually filling out the fields above: https://tommcfarlin.com/get-posts-with-multiple-taxonomies/
You also need to replace
123
with the ID of the list you’re targeting.September 20, 2019 at 4:05 am #1014304webcréateurThank you so much! This works perfectly.
However, I obviously had the wrong approach to our requirement. With this approach we would have to create at least one new snippet (as above) and lots of WPSP lists for each output.
Our goal is to output a certain issue (about 50 news items) — structured by category – in an archive template.Do you have any ideas how best to solve the requirement?
I absolutely wanted it to work with WPSP, apparently it doesn’t work as I wanted …
September 20, 2019 at 10:01 am #1014679TomLead DeveloperLead DeveloperHmm, I can’t think of a way to do it automatically like that.
Do you have any examples of the page you’re trying to build?
September 21, 2019 at 5:54 am #1015127webcréateurI just posted an URL in the edit Post area.
This link directly opens an Issue in an archive template.
We are trying to output the single post of the issue structured by category — in an archive template.
<?php /** * The template for displaying Archive pages. * * @package GeneratePress */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } get_header(); ?> <div id="primary" <?php generate_do_element_classes( 'content' ); ?>> <main id="main" <?php generate_do_element_classes( 'main' ); ?>> <h3 class="widget-title">Economy</h3> <?php if ( function_exists( 'wpsp_display' ) ) wpsp_display( 38852 ); ?> <h3 class="widget-title">Politics</h3> <?php if ( function_exists( 'wpsp_display' ) ) wpsp_display( 38852 ); ?> <h3 class="widget-title">Culture</h3> <?php if ( function_exists( 'wpsp_display' ) ) wpsp_display( 38852 ); ?> <h3 class="widget-title">Sports</h3> <?php if ( function_exists( 'wpsp_display' ) ) wpsp_display( 38852 ); ?> <h3 class="widget-title">ETC</h3> <?php if ( function_exists( 'wpsp_display' ) ) wpsp_display( 38852 ); ?> </main><!-- #main --> </div><!-- #primary --> <?php /** * generate_after_primary_content_area hook. * * @since 2.0 */ do_action( 'generate_after_primary_content_area' ); generate_construct_sidebars(); get_footer();
September 21, 2019 at 6:24 pm #1015598TomLead DeveloperLead DeveloperHmm, I can’t think of a way to automatically do it. If you can find a tutorial (I’m sure one exists) on how to do with a custom loop, I may be able to help figure out how to do it inside WPSP.
September 22, 2019 at 1:00 am #1015695webcréateurThis might be a possible solution?
https://hookagency.com/display-posts-in-archives-pages/#modify-theme
The code queries the correct posts from the CPT “issue” but from all categories and not only a specific category.
<div class="posts-wrapper"> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <article id="post-<?php the_ID(); ?>" <?php if(is_category('featured')): ?>class="featured-post"<?php endif; ?>> <h1 class="post-title"><?php the_title() ;?></h1> <p class="date-and-category"> Published on <?php the_time('M j, Y'); ?> by <?php the_category(', '); ?> in <?php the_category(', '); ?> </p> <div class="post-content"><?php the_content(); ?></div> <div class="prev-next-links"> <ul> <li class="next-post"><?php next_post_link(); ?></li> <li class="prev-post"><?php previous_post_link(); ?></li> </ul> </div> </article> <?php endwhile; else: ?> <p>Sorry, this post does not exist</p> <?php endif; ?> </div>
September 22, 2019 at 1:09 am #1015698webcréateurMaybe this one? I am still testing:
https://artisansweb.net/display-posts-specific-category-wordpress-page/
September 22, 2019 at 1:58 am #1015711webcréateurUnder the website URL (only admins can see) you can see now that all posts and categories are listed from the correct issue.
<div class="posts-wrapper"> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <article id="post-<?php the_ID(); ?>" <?php if(is_category('featured')): ?>class="featured-post"<?php endif; ?>> <h3 class="post-title"><?php the_title() ;?></h3> <p class="date-and-category"> Published on <?php the_time('M j, Y'); ?> by <?php the_author(', '); ?> in <?php the_category(', '); ?> </p> </article> <?php endwhile; else: ?> <p>Sorry, this post does not exist</p> <?php endif; ?> </div>
So is it possible to query categories one by one to be able to add dividers as a headline?
<h3 class="widget-title">Category Economy</h3>
– all posts from category Economy
September 22, 2019 at 10:20 am #1016013TomLead DeveloperLead DeveloperYou would need to create a bunch of different queries, each one grabbing posts from a different category.
You can learn more about queries here: https://www.smashingmagazine.com/2013/01/using-wp_query-wordpress/
This tool might be helpful: https://generatewp.com/wp_query/
September 23, 2019 at 10:22 am #1016926webcréateurThank you very much so far!
I am not a pro, probably I will need some time to figure out to set queries, each one grabbing posts from a different category.
Hope you than help to figure out how to do it inside WPSP like mentioned before.
-
AuthorPosts
- You must be logged in to reply to this topic.