I searched the internet for a possible solution but wasnt able to find one.
The Labels of linked products in a grouped product apear like:
[:de]german value[:en]english value[:]
My goal is to get the title/label in the current languge of my site
do I need to edit the call of my label in grouped.php?
if you need any further information tell me.
You have to edit grouped.php inside /wp-content/themes/YOUR_THEME/woocommerce/single-product/add-to-cart/grouped.php
Wrap all the instances of $grouped_product->get_name() into a __() function.
In my case I had the following code in grouped.php:
<?php echo $grouped_product->is_visible() ? '<a href="' . esc_url( apply_filters( 'woocommerce_grouped_product_list_link', get_permalink( $grouped_product->get_id() ), $grouped_product->get_id() ) ) . '">'
. $grouped_product->get_name() . '</a>' : $grouped_product->get_name(); ?>
so I used the translation function __() to get rid of qTranslate-X language tags:
<?php echo $grouped_product->is_visible() ? '<a href="' . esc_url( apply_filters( 'woocommerce_grouped_product_list_link', get_permalink( $grouped_product->get_id() ), $grouped_product->get_id() ) ) . '">'
. __($grouped_product->get_name()) . '</a>' : __($grouped_product->get_name()); ?>
Related
Currently it add nofollow at all products across website, how to make it at is_front_page() only?..
function woocommerce_template_loop_product_title() {
echo '<p class="name product-title ' . esc_attr( apply_filters( 'woocommerce_product_loop_title_classes', 'woocommerce-loop-product__title' ) ) . '">' . get_the_title() . '</p>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
Change the value of your rel attribute. So, when the user is at the frontpage, rel will have a value of nofollow. Otherwise, the value will be "" empty.
<?php
function woocommerce_template_loop_product_title() {
// Add the $nofollow
$nofollow = "";
if(is_front_page() ){
$nofollow = "nofollow";
}
echo '<p class="name product-title ' . esc_attr( apply_filters( 'woocommerce_product_loop_title_classes', 'woocommerce-loop-product__title' ) ) . '"><a href="' . get_the_permalink() . '" rel='.$nofollow.'>' . get_the_title() . '</a></p>';
?>
I need to display sub categories from a particular category
<?php
$subcategories = get_categories('&child_of=22&hide_empty');
foreach ($subcategories as $subcategory) {
echo '<a href="' . get_category_link( $subcategory->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $subcategory->name ) . '" ' . '>' . $subcategory->name.'</a>';
echo '<p>'.$subcategory->description.'</p>';
}
?>
I tried this
echo '<img class='hline' src='bloginfo('template_url')/img/hline.png' alt=''>';
its not working
You need to look at the basics of strings and concatenation in PHP.
You open your string with single quotes so you can't then use single quotes for HTML attributes unless you escape them first (\'hline\'). Instead you should be using double quotes for those attributes.
Then you need to break out of your string in order to use your PHP function, bloginfo(). With that said it makes more sense to use get_template_directory_uri() instead (or stylesheet directory depending on your setup).
Complete example:
echo '<img class="hline" src="' . get_template_directory_uri() . '/img/hline.png" alt="" />';
Documentation: http://php.net/manual/en/language.types.string.php
I would use instead:
get_template_directory_uri()
And I like to write it like this but that depends internally on you.
<img class="hline" src="<?php echo get_template_directory_uri();?>/img/hline.png" alt="" />';
I am trying to create a plugin what will be a sime kind of a comments archive.
I have looked at get_comment().
I am looking to show where the comment came from, specifically the title of the post where the comment is attached. This is part of my code:
if ( $comments ) {
foreach ( $comments as $comment ) {
// here you can display the comment in the way you want
echo 'from: ' . $comment->i want comment post title here . '<br/>';
echo '<p>' . $comment->comment_content . '</p>';
}
}
How to do this?
Here is how you do it:
<?php
if ( $comments )
foreach($comments as $comment){
// here you can display the comment in the way you want
echo 'from: ' . get_the_title($comment->comment_post_ID) . '<br/>';
echo '<p>' . $comment->comment_content . '</p>;
}
?>
if ( $cat ) echo '<a class="custom-cat-btn" href="#cat-' . $cat . '">More ' . get_cat_name($cat) . ' Posts</a>';
This gives me:
http://mydomain.com/#cat-127
But I get a 404 when I click on the link
Can anyone help me get the actual link please
Thanks
You can retrieve the category link with get_category_link
So,
if ( $cat ) echo '<a class="custom-cat-btn" href="' . esc_url( get_category_link( $cat ) ) . '">More ' . get_cat_name($cat) . ' Posts</a>';
Is it possible in wordpress when I call example.com/category to have listed all available categories. If I request the url like in my example I'm getting an 404 page
I'm not sure if there is a default link to list all the categories.
But it doesn't mean you can't do it yourself. Create a new template file in your theme, name it for example category_list.php and add this code:
You might want to tweak it a bit to display it how you want.
<?php
/**
* Template Name: Category listing
* Description: list all the categories
*/
get_header(); ?>
<div class="container">
<?php
$args=array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories=get_categories($args);
foreach($categories as $category):
echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
echo '<p> Description:'. $category->description . '</p>';
echo '<p> Post Count: '. $category->count . '</p>';
echo '<hr />';
endforeach;
?>
</div>
<?php get_footer(); ?>
Then go to Pages -> add new. Name the Page as "Category", so that the url will be example.com/category.
And in the template list select the template you just created. It will be named "Category listing" as you can see in the code above in the comments at the top.