Forum Replies Created
-
AuthorPosts
-
Good morning,
Thanks for that. That bit you pasted above made me realise that there is code in there that used to be commented out, but it snow part of the live code. I think it was something copied from the internet that was supposed to be temporary. A few weeks ago the website crashed and i had to revert to an old website backup, im guessing tis file was part of the backup.
In any case im confident that i can figure it out from here.
thanks for your help, much appreciated.
hello, i think the custom code was for displaying custom fields on the post grid. i have pasted hte whole file below but you can find a copy of it on the link i sent above.
thanks for your help
hey, thanks for the tip. I started looking into it and found that the problem is with the postslider.php file in my child theme.
unfortunaltely this was a file that was customised with help from your support team a couple years ago. I have no idea whats what. It seems quite different from the new theme file and i cant really tell what part of the update and what was customisation.
i have made a copy of the file and uploaded it where you can find it, link below
Thanks Mike,
Unfortunately that was the first thing i tried, i reverted back to 4.8 when things started breaking. Apologies i forgot to update it again.
I have updated again to 5.5 but the problem persists.
Hey,
I have made a copy of the website, login below. I have tried disabling other plugins etc but couldn’t get it working.
ok thanks. details below
It seems that now every post has ‘Array” just under the title. The placement is good but i don’t know why they all say ‘Array’.
I added a custom field called price and a value. Also tried with a capital P but same result.
Do i need to use ACF to do this? im just using the built in custom field options.
Also am i still supposed to add the first chunk of code you added? where does that go? everywhere i put it i get the error “syntax error, unexpected ‘,’ expecting t variable’. If i save it anyway the website crashes.
sorry was logged in with wrong account
The custom post is called ‘Advertisements’ and there are a bunch of taxonomies. The one that i am most interested in customizing is called ‘Price’ and i don’t really know what you mean about terms? each product has a different price?
Essentially its a custom post with a price associated with it. I need that to show up on the postslider.php when i list all the posts.
It seems that now all the taxomonies have a class of stray.
I change this:
if(in_array($term->name, array(“kitty”, “pussy”, “catty”))) {
$cat_class = “pets”; }
to be:if(in_array($term->name, array(“price”, “Price”))) {
$cat_class = “price”; }so that it matched the taxonomy im looking at. However its still has ‘stray’ as a class instead of ‘price;
Thanks Ismael,
That makes sense, but the problem now is that its only showing one taxonomy – the brand. All the other are no longer visible.
Another problem is that its using the brand name rather then the taxonomy name. For example it looking for a brand called brand1 and giving it the class i have assigned, but its ignoring brand2 etc. So if i apply this to the product price, I cant give a class to all prices, only one particular number?
ok i see, sorry i dont know php at all and i am fumbling through without a clue. I have taken the example you sent and replaced the the terms with myown, however is still don’t know hoe to incorporate it into the $cats variable:
$terms = get_the_terms( get_the_ID(), ‘price’ );
if ( $terms && ! is_wp_error( $terms ) ) :
$price_links = array();
foreach ( $terms as $term ) {
$price_links[] = $term->name;
}
$price = join( “, “, $price_links );
?>
<p class=”price”>
<?php printf( esc_html__( ‘price: <span>%s</span>’, ‘textdomain’ ), esc_html( $price ) ); ?>
</p>
<?php endif; ?>I tired pasting the above into several places of the postslider.php file but it just causes fatal errors everywhere and breaks the whole site. Unfortunately its not as straight forward as a page template.
also tried the below code which seems to add a number 1 after the other terms on the front end, but only on the first product:
if( ! empty( $title ) || in_array( $show_meta_data, array( ‘always’, ‘on_empty_title’ ) ) )
{
if( true )
{
$taxonomies = get_object_taxonomies( get_post_type( $the_id ) );
$cats = ”;
$excluded_taxonomies = array_merge( get_taxonomies( array( ‘public’ => false ) ), array(‘post_tag’,’post_format’, ‘show’, ‘seller’, ‘selleremail’, ‘show_wanted’, ‘price’) );
$excluded_taxonomies = apply_filters( ‘avf_exclude_taxonomies’, $excluded_taxonomies, get_post_type( $the_id ), $the_id );
$terms = get_object_term_cache( $post->ID, $taxonomy );
$term_ids = wp_list_pluck( $terms, ‘price’ );if( ! empty( $taxonomies ) )
{
foreach( $taxonomies as $taxonomy )
{
if( ! in_array( $taxonomy, $excluded_taxonomies ) )
{
$cats .= get_the_term_list( $the_id, $taxonomy, ”, ‘, ‘, ” ) . ‘ ‘;
$cats .= wp_cache_add( $post->ID, $term_ids, $taxonomy . ‘price’ );}
}
}Thanks for the response Ismael,
The example given says i need to add the taxonomy term_id, is that the same as the slug?And the postslider.php file adds everything to the $cats variable to make it show on the front end. So to add the ‘price’ taxonomy i would do this?
$cats .= wp_cache_add( $post->ID, $term_ids, $taxonomy . ‘price’ );Here is the whole code i added, but it seems to break the whole website so i had to remove it.
function get_the_terms( $post, $taxonomy ) {
$post = get_post( $post );
if ( ! $post ) {
return false;
}$terms = get_object_term_cache( $post->ID, $taxonomy );
if ( false === $terms ) {
$terms = wp_get_object_terms( $post->ID, $taxonomy );
if ( ! is_wp_error( $terms ) ) {
$term_ids = wp_list_pluck( $terms, ‘price’ );
$cats .= wp_cache_add( $post->ID, $term_ids, $taxonomy . ‘price’ );
}
}actually one more thing,
is there a way to tell which template i need to edit for specific archives? the archive pages for my custom posts are not displaying the ‘read more’ link. For example, compare the home page which uses postslider.php, to the page linked below
all good you can close this
Perfect!
Thanks Ismael everything is working great
I have reset the password below. It shouldn’t expire, its not a temporary account.
Thanks i was able to edit the array and remove unwanted taxonomies, however the duplicates are still there.
Yes i reverted the to the original postslider.php before updating the new one in my child theme. I even tried downloading the theme again and copied the fresh file to my theme to make sure its the same as the original. I used an online diffchecker to make sure that the two files are exactly the same except for the code to show the taxonomies.
Also,
The code given to me is showing duplicates. For example the first post shows all the taxonomies once, the second post shows all the taxonomies of the first post AND second post, the third post shows the taxonomies of the first, second and third post etc.
Actually ignore that, i regenerated the thumbnails about 100 times and it finally worked. Not sure why it wasn’t working earlier since i changed browser to avoid caching issues. In any case everything is working as expected now so you can close this .
thanks
Hello,
I have tried using a much larger photo but it didn’t make a difference. I even tried to install the simple image sizes plugin that you recommended but the photos are still being cropped.
i have remade a login for you below
Thank you, however only the first post is displaying correctly, all the the other posts show the word “Array” in front of the list of taxonomies?
For example :
ArrayBrand 1instead of just:
Brand 1Hi Ismael,
I have tried this:
1. completely re-uploaded new images
2. used the media replace plugin to replace the existing images
3. used the regenerate thumbnails pluginThe original size of the photo ( the last photo that i tested ) is 500×900 pixels. I get that this is not a square photo, but i will be relying on clients uploading these images so i can’t manually crop photos for everyone. I just need the featured image to not crop photos, even if it means having a smaller photo.
Your a legend! that works perfectly. This has been plaguing me for weeks.
Now to add the other taxonomies i repeated the whole chunk of code above and replaced the taxonomy name. It works but there will about 8 taxonomies to display so that’s a lot of code, is there a way to condense it?
Hi Ismael,
Sorry for the slow reply, i have been preoccupied with the other thread. I have added the code you gave me to functions.php and played with the image sizes, however the image still gets cropped regardless of the size. I have tried changing the size of the image containers and overlay image etc using css but even if the container is much larger than the photo it still gets cropped?
ok its working now, it must have been my browser acting up. However its still not showing on the home page?
Hi Ismael,
Something strange has happened. When i first visited your link it looked like it worked. I could see ‘Brand: Brand 1’. However after a refresh it disappeared? I can see the code you entered to the postlisder.php file is still there. Not sure why its not showing, i have cleared my browser cache.
Also, It didn’t appear on the website home page where all the advertisements are displayed. Will this only work on individual taxonomy archive pages or should this work on the home page too?
Hello,
The slug is just brand-1, brand-2 brand-3 etc. I have added a new password for the login below. You can findall the taxonomies by visiting the Advertisements tab.
I tried adding the above code to postslider.php but it gave me a syntax error: unexpected T_constant_Encapsed_string, i played around with the quotation marks but it was giving me wierd results on the front end. Not sure where i went wrong. I have added anther link below with a copy of the postlisder.php file and single.php file so give you a better picture of what i am working with.
Hopefully that helps?
I think the problem is the syntax of the php. I don’t really know enough about php to be sure, but by the look of it i shouldn’t need to open the php tags before ‘the terms..’
Since this whole thing is happening inside the $output variable.
$output .= ! empty( $excerpt ) ? “<div class=’slide-entry-excerpt entry-content’ {$markup}>
<p>terms should show here:<?php the_terms( $post->ID, ‘brands’, ‘Brand: ‘, ‘, ‘, ‘ ‘ ); ?></p>{$excerpt}</div>” : ”;
$output .= ‘</div>’; -
AuthorPosts