fibbo8
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: Retrieve list of categories inside date.php templateOk! This works.
I can’t make a comparison now, but I think I was mistaking somenthing when passing the arguments to the function.Another couple of questions ??
I’ve a second custom taxonomy and I’d like to do the same “filter” that I’ve done referencing the query string for year.
So I’ve set another query var and I’ve modified the code above in something like.
The code works. I can able to filter the posts that share the year and the brand, or the price and the brand.$archive_year = get_query_var('anno-rif'); $archive_price = get_query_var('prezzo'); $terms = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); if (empty ($archive_year) && empty ($archive_price)) { $posts_in = get_posts() } // arguments for the general loops on taxonomy term if (isset($archive_year)) { $posts_in = get_posts() } //arguments for filter according year if (isset($archive_price)) { $posts_in = get_posts() } //arguments for filter according price
But I can’t well imagine if this setup will simply mess the code or if it also will cause problems.
At the beginning of this prolific discussion you have spoke about security concerns when using the query string.
In functions.php I’ve simply write:function query_var_anno( $vars ){ $vars[] = 'anno-rif'; return $vars; } add_filter( 'query_vars', 'query_var_anno' );
Inside the templates this function is invoked as above.
Does where does come the issues?
Forum: Developing with WordPress
In reply to: Retrieve list of categories inside date.php templateI think so too that an URL’s structure with the query args is better to manage.
In some cases it is used also in big sites, like Amazon or Ebay.I’ve tried to used also Wp_Query, but it seems not to work in my code.
Not insisted that much to understand where I mistaked, because I’ve changed only the function and the code began to work.
Maybe this setup is more “scratch” and “resource hungry”, but I proceed with small steps ??Forum: Developing with WordPress
In reply to: Retrieve list of categories inside date.php templateHi!
thanks again.
Finally I try for your first advice. Now on the taxonomy.php I can show the post filtered according year.
If is used get_posts function to retrieve the posts, WP is able to “interpret” the parameter for the year inserted in the URL. I can’t be able to do the same using WP_query.In my opinion this is a better setting from the point of view of navigation.
Now the URL for the cat-a:
mysite.com/marca/cat-a?anno-rif=2013
My doubt is if Google’s crawler is able to “construct” this URL structure or if I need to implement a rewrite rule to give the possibility to indexing these pages.<div class="col-md-10 hidden-sm hidden-xs" id="col-post"> <?php $anno_imm = get_query_var('anno-rif'); $terms_imm = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); if(!empty($anno_imm)) { // check if user "arrive from date.php and show the year echo '<h2 class="text-center title">Auto marca ' .$terms_imm->name. ' immatricolate ' .$anno_imm. '</h2>'; } else { echo '<h2 class="text-center title">Auto marca ' .$terms_imm->name. '</h2>'; } ?> <section> <div class="row"> <?php $archive_year = get_query_var('anno-rif'); $terms = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); $posts_in = get_posts( array ( 'post_type' => 'marca', 'orderby' => 'date', 'order' => 'ASC', 'tax_query' => array(array( 'taxonomy' => 'tassonomia_marca', 'field' => 'slug', 'terms' => $terms->slug ) ), 'date_query' => array( 'year' => $archive_year ) ) ); foreach ( $posts_in as $post_object ) { setup_postdata( $GLOBALS['post'] =& $post_object ); ?> <div class="col-md-2 view-arch"> <li> <?php /* Display the thumbnail only when available. */ if ( has_post_thumbnail() ) : ?> <a class="example-image-link" data-lightbox="example-set" data-title="" title="<?php the_title_attribute(); ?>" href="<?php the_permalink(); ?>"> <?php the_post_thumbnail(); ?> </a> <?php /* Remember that we had a conditional check open; close it. */ endif; ?> </li> <p><?php the_title() ?></p> </div> <?php } wp_reset_postdata(); // like wp_reset_query() but for $post ?> </div> </section>
Forum: Developing with WordPress
In reply to: Retrieve list of categories inside date.php templateHi bcworkz,
thank again for your reply.
Don’t worry, your explanations are always good and give me many insights.
I’ll give also these tries, hoping to create something.I’ve also tried for another solution. It roughly works, but I think is not the best from a point of view of SEO and navigation. An archive build the way your post explains would be much more user-friendly and SEO-friendly.
Basically I’ve continued to use the date.php template. I’ve transformed each element of the list of category in a <h2> element, then I’ve used them as a title for a section where I’ve retrieved the posts belonging to that category.
I’ve some problems with pagination, but the biggest problem is that the URL
remain:
mysite.com/2013/?post_type=marca
mysite.com/2013/page/2/?post_type=marcaSo I will try to implement this other solution.
Thanks for your help!Forum: Developing with WordPress
In reply to: Retrieve list of categories inside date.php templateThanks! ^_^
But I haven’t really finished all the work -_-
I’ve retrieve this list of term inside a date.php template, after I’ve chosen a year from a menu.If click on cat-A term it brings me (correctly) to mysite/custom-taxonomy/cat-a,
where I can see all the posts belonging to that category.
But I need only the posts of cat-a published in that certain year.
Is there a way to retrieve the reference for the year to set the ‘date_query” argument in the archive.php or in the taxonomy-custom_taxonomy template?Forum: Developing with WordPress
In reply to: Retrieve list of categories inside date.php templateI think I’ve reached what I need.
Maybe it isn’t optimizated, but it works.<?php global $post; $archive_year = get_query_var('year'); $args = array( 'taxonomy' => 'tassonomia_marca', 'post_type' => 'marca', 'orderby' => 'name', 'order' => 'DESC', 'date_query' => array( 'year' => $archive_year ) ); $posts = get_posts($args); $cachearray = array(); if ($posts) { foreach ( $posts as $post ) { setup_postdata( $post ); $terms = wp_get_post_terms($post->ID, 'tassonomia_marca',array("fields" => "all")); foreach($terms as $term) { if ($term->parent == 0 && is_array($cachearray)) { //check for parent terms only and empty array $cachearray[] = $term; } } } wp_reset_postdata(); } $results = array_unique($cachearray, SORT_REGULAR); foreach($results as $result) { $term_link = get_term_link( $result ); echo '<li class="cat-item" style="list-style: none;"><a href="' . esc_url( $term_link ) . '">' . $result->name . '</a></li>'; } ?>
Forum: Developing with WordPress
In reply to: Retrieve list of categories inside date.php templateHi!
Thanks for your new reply.
Theory perfectly explained. Now I have a stronger idea of how differently work the two functions and how I can try to use them.
I’ll give new tries following your advices.
Thanks again
Forum: Developing with WordPress
In reply to: Retrieve list of categories inside date.php templateI’ve made two tries, but in both cases I don’t get what I want.
I’ve tried to use two different functions, but I’m stuck on how change them.With the following snippet I use get_terms and can retrieve all the terms of the custom taxonomy. It seem to ignore the year.
global $post; $archive_year = get_query_var('year'); $args = array( 'taxonomy' => 'tassonomia_marca', 'post_type' => 'marca', 'orderby' => 'name', 'order' => 'DESC', 'date_query' => array( 'year' => $archive_year ) ); $posts = get_posts($args); if ($posts) { $terms = get_terms( array( 'taxonomy' => 'tassonomia_marca', 'hide_empty' => true, ) ); foreach($terms as $term) { if ($term->parent == 0) { //check for parent terms only $term_link = get_term_link( $term ); echo '<li class="cat-item" style="list-style: none;"><a href="' . esc_url( $term_link ) . '">' . $term->name . '</a></li>'; } } wp_reset_postdata(); }
With this second snippet I use wp_get_post_terms anche I can retrieve the terms associated to the posts of a certain year.
The drawback is that I obtain a list where there are “duplicated”. If there are two posts associated to “Cat A”, “Cat A” appeares two time in the list.global $post; $archive_year = get_query_var('year'); $args = array( 'taxonomy' => 'tassonomia_marca', 'post_type' => 'marca', 'orderby' => 'name', 'order' => 'DESC', 'date_query' => array( 'year' => $archive_year ) ); $posts = get_posts($args); if ($posts) { foreach ( $posts as $post ) { setup_postdata( $post ); $terms = wp_get_post_terms($post->ID, 'tassonomia_marca', array("fields" => "all")); foreach($terms as $term) { if ($term->parent == 0) { //check for parent terms only $term_link = get_term_link( $term ); echo '<li class="cat-item" style="list-style: none;"><a href="' . esc_url( $term_link ) . '">' . $term->name . '</a></li>'; } } } wp_reset_postdata(); }
Any hint on how could change the snippet?
Forum: Developing with WordPress
In reply to: Retrieve list of categories inside date.php templateHy bcworks,
thanks for your reply.
I get an idea of what you’ve explained.
I’m not a programmer, but I’m giving it a try to reach something.Forum: Fixing WordPress
In reply to: Polylang doesn’t set on home pageExcuse me!
Forum: Fixing WordPress
In reply to: Quirk redirect after loginHy Belly,
thanks again for your reply. You’ve been helpful.
I’m not a developer and I’ve got to arrive to some results with many tries, but now it seems that redirects work like I’ve expected.I’ve follow the cue of your linked post, but made a little change.
In my case the redirect worked if I defined the “href” omitting the $_SERVER[“HTTP_HOST”] paramater:
<a href="<?php echo wp_login_url($_SERVER['REQUEST_URI'] ); ?>"
To maintain the redirect on backend dashboard for the admin I’ve put this function in function.php:
function my_login_redirect( $url, $request, $user ){ if( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) { if( $user->has_cap( 'administrator' ) ) { $url = admin_url(); } } return $url; } add_filter('login_redirect', 'my_login_redirect', 10, 3 );
Forum: Fixing WordPress
In reply to: Quirk redirect after loginHi Belly!
Thank you for your reply.
I tried your snippet for a page and it works perfectly.
I’ve tried to modified it, because of the structure that I’ve on the test site.
My idea was to create some pages accessible only by logged user, but those page haven’t necessarily to be under the same path.
For example I can have https://www.testsite.com/private-page and https://www.testsite/company/private-pageSo I tried to change the $url = home_url(‘/members-only/’); in $url = get_previous_posts_link(); because the user can login both from https://www.testsite.com/private-page and https://www.testsite/company/private-page.
But in this case the redirect drive to the backend profile.
Forum: Fixing WordPress
In reply to: Problem with Flexisel.jsHi hudson.
Thank for your reply and excuse my late response.
I’m still testing WordPress on a local installation.
As a workaround I can use the carousel, but I’d like that plugin that I’ve tried on other sites and I’d like to understand why it can’t reach the images.Forum: Fixing WordPress
In reply to: Php script inside templateHi!
The directory from which I try to pick the images, is a subdirectory inside the themes/MYTHEMES/images/ directory