Wordpress Different Title Image in Category/Archive page - wordpress

I would to ask how can I have a different background image for each post category in my category template. My category template is custom.
Ex.
My post category is Living Room and I want an image of living room and another post category is Bedroom and I want a bedroom image and so on for all my categories.
Thank you in advance.

You can use ACF Plugin create a or more field and put code to Archive or Category file in your Template
Read Document Tip ACF Category here

As mentioned by #dinhcode you can use advanced custom fields to add custom fields to your category taxonomy and use this field to setup images for the taxonomy term and then get the image object/url (whatever you have set as output while creating the field in acf).
Below is a small sample code:
get_header();
// get the current taxonomy term
$term = get_queried_object();
// assuming you have used image as field name and the output is set to url
$image = get_field('image', $term);

Related

How to add custom fields in invoice and wordpress backend?

I am working on a wocommerce website, and i want to display a tax that will be custom calculated eg: (weight0.660+price=taxquantity) i am using this formula for custom fields calculation. now i want to display the calculated output on user invoice when user checks out. please help me with this
I am using ACF pro plugin to create custom fields and add custom formula.
You need to find the template for the invoice and add
<?php echo get_field('fieldname', $id); ?>
fieldname will be the name of the ACF field and $id will need to be the post id for wherever the field is

woocommerce empty product name field

I'm using WooCommerce 2.3.8 and WordPress 4.2.1. Is there a way to remove the product title from an individual product? I used to be able to just put a blank space and the product title would be blank, but now it doesn't let me, it just keeps putting the original product title back in when I update the product. This is only for one category of products. I would like to have a category page of products that have no titles, just the featured images in a grid.
Thank you!
1. Dirty Solution
Use CSS:
All of your list items for a product on a category have css classes named after the categories' name e.g. product_cat-mycatgegory.
You can find the product's title within an <h3> element.
Therefore the following CSS Code would prevent displaying the product's title on the category page.
.product_cat-mycatgegory h3{
display:none;
}
Note that the product title is be still readable via the browser's inspector.
2. Cleaner Solution
You could edit the content-product.php template. Check if a current category is chosen and decide whether to show the title or not. Please check woocommerce's documentation about template structure and overriding.
Pseudocode
<?php
$cat_obj = $wp_query->get_queried_object();
$category_ID = $cat_obj->term_id;
if(!($category_ID == category_ID_without_titles)) :?>
<h3><?php the_title(); ?></h3>
<?php endif;?>

WordPress: display full post AND excerpts on one page

Is there a way my category archive display both full posts and excerpts?
What I want is the first two or three latest posts display as full content posts, and all the others as excerpts with just title and a read more button. These are displayed on one page. I am currently using a category archive, on the twentyfifteen theme.
I know I can set a page to either display full or just excerpts, but not a combination. Is this possible?
Thanks!
You can get these in your wordpress loop on page or post.
<?php
$content = get_content($post->ID); //full content of post
$excerpt = substr($content,0,150); //you can limit charaacter like 150
?>

How to make Wordpress Category menu items display the category as title?

I have been looking for this function everywhere but cannot seem to find a clear way to do it.
I have created a blog with a category-based menu but I was wondering how I could get the menu item to display its category as a title whenever it is clicked. I need this because on my website I have post items which share the same category therefore I need to be able to tell the user of his/her location. Once the user clicks on the post however, it is the first category which will be displayed as a title and this seems to be working with:
$category = get_the_category();
echo $category[0]->cat_name;
The only time that this is a problem is when the posts that share the categories do not have their main category listed first.
I hope that I am making myself clear,
Thanks.
You can look at the category slug in the URL, and get the category by its slug.
$cat = get_category_by_slug( $slug );
echo $cat->name;
http://codex.wordpress.org/Function_Reference/get_category_by_slug

WORDPRESS: Disable comments in "News" Category and Enable in "Blog" Category?

I have a News page that displays all the posts within the "News" Category. This category has sub-categories such as "Merchandise, Music, Events" ect.
I am aiming to remove comments from ALL News/Sub-category posts but only display them with the "Blog" Category posts.
Right now I have my single.php set up so posts with the "Gallery" post_format structure are displayed differently.
Here is the single.php file//
http://pastebin.com/YNf3TxT6
I am wondering what I have to fix in order to get this working...
Edit: For future viewers, here is the updated paste from the conversation below for a single.php that will only show the comments template if the post is in the "Blog" Category: pastebin.com/y9ZtCN5U
Assuming you put your Blog posts on a page separate from your news posts, you should be able to use different templates based on category.
http://codex.wordpress.org/Category_Templates
So, you could make a category-blog.php template file that doesn't include the comments code.
If all of your categories are being listed on the same page, use this instead of the in_category stuff on line 50.
<?php
foreach (get_the_category() as $category) {
if ( $category->name == 'Blog' ) {
comments_template();
}
}
?>
Not 100% sure that will work, but try it out and let me know what happens.

Resources