wmaraci reklam
lidertakipci

Wordpress nasıl birden fazla single-product yapılır?

19 Mesajlar 1.210 Okunma
advertseo
wmaraci reklam

MustafaZahit MustafaZahit WM Aracı Kullanıcı
  • Üyelik 27.06.2018
  • Yaş/Cinsiyet 30 / E
  • Meslek Öğrenci
  • Konum Mersin
  • Ad Soyad Z** Z**
  • Mesajlar 307
  • Beğeniler 15 / 32
  • Ticaret 0, (%0)
Merhabalar temada şunu nasıl yapabilirim?
Normalde wordpress woocommerece de ürünü ekliyoruz ve ürünü incele dediğimizde bizi ürün bilgisinin ve satın al veya kaç adet olacağını seçtiğimiz ekrana yönlendiriyor bu ekranı woocommerece dosyasının içindeki single-product.php ile düzenleyebiliyorım benim sorum şu,
X kategorisinde olanları single-product-x.php ye yönlendirsin gerisini normal single-product.php yönlendirsin bunu nasıl yapabilirim ? Teşekkür ederim hocalarım
bilimokur WpÖmerFaruk Ecancan cgrclk

Not : bu linke baktım alt linklerine baktım yapamadım maalesef
https://stackoverflow.com/questions/25789472/woocommerce-how-to-create-multiple-single-product-template-based-on-category
 

 

wmaraci
reklam

wpuzman wpuzman WordPress Developer Kullanıcı
  • Üyelik 13.01.2017
  • Yaş/Cinsiyet 32 / E
  • Meslek Yazılım
  • Konum Trabzon
  • Ad Soyad B** M**
  • Mesajlar 2773
  • Beğeniler 293 / 949
  • Ticaret 33, (%100)








single-product.php içerisinde bu kısmı düzenleyerek yapabilirsin. Önce var olan kategorinin id sini al. Sonra if koşuluyla farklı şablon çağır.

Mesela

if ($catID == 1):
wc_get_template_part( 'content', 'single-product-custom' );
else:
wc_get_template_part( 'content', 'single-product' );
endif;
 

 

MustafaZahit MustafaZahit WM Aracı Kullanıcı
  • Üyelik 27.06.2018
  • Yaş/Cinsiyet 30 / E
  • Meslek Öğrenci
  • Konum Mersin
  • Ad Soyad Z** Z**
  • Mesajlar 307
  • Beğeniler 15 / 32
  • Ticaret 0, (%0)

bilimokur adlı üyeden alıntı









single-product.php içerisinde bu kısmı düzenleyerek yapabilirsin. Önce var olan kategorinin id sini al. Sonra if koşuluyla farklı şablon çağır.

Mesela

if ($catID == 1):
wc_get_template_part( 'content', 'single-product-custom' );
else:
wc_get_template_part( 'content', 'single-product' );
endif;


Hocam kodu şöyle ekledim fakat sayfanın üst tarafında il woocomerrecenin tasarımı çıktı altında ise benim yaptığım tasarım çıktı yani iki tane yükledi ve benim oluşturduğum
single-product-custom.php 'nin içindeki kodların hiç birini okumadı maalesef, kategori ID'si doğru hocam


wc_get_template_part( 'content', 'single-product-custom' );
else:
wc_get_template_part( 'content', 'single-product' );
endif; ?>





Ek olarak hocam şunu fark ettim, sizin verdiğiniz kod bende yok sadece " " bu var.

--> " " bu kısmı eklediğim zaman ek olarak ilk woocommerece tasarımını benimle alakası olmayan bir tasarımı sayfanın en üst kısmına ekliyor altınada benim tasarımımı ekliyor 2 tane oluyor yani
 

 

wpuzman wpuzman WordPress Developer Kullanıcı
  • Üyelik 13.01.2017
  • Yaş/Cinsiyet 32 / E
  • Meslek Yazılım
  • Konum Trabzon
  • Ad Soyad B** M**
  • Mesajlar 2773
  • Beğeniler 293 / 949
  • Ticaret 33, (%100)
$catID yi ben temsili yazdım :) ürünün kategorisini kendiniz bulup $catID ye atayacaksınız.
 

 

wmaraci
wmaraci

MustafaZahit MustafaZahit WM Aracı Kullanıcı
  • Üyelik 27.06.2018
  • Yaş/Cinsiyet 30 / E
  • Meslek Öğrenci
  • Konum Mersin
  • Ad Soyad Z** Z**
  • Mesajlar 307
  • Beğeniler 15 / 32
  • Ticaret 0, (%0)

bilimokur adlı üyeden alıntı

$catID yi ben temsili yazdım :) ürünün kategorisini kendiniz bulup $catID ye atayacaksınız.


hocam ek olarak güncelleme yaptım bakarmısınız üst yoruma, catID'yi buldum 98 oraya eklemeyecekmiyim yanlış mı yapmışım hocam
 

 

wpuzman wpuzman WordPress Developer Kullanıcı
  • Üyelik 13.01.2017
  • Yaş/Cinsiyet 32 / E
  • Meslek Yazılım
  • Konum Trabzon
  • Ad Soyad B** M**
  • Mesajlar 2773
  • Beğeniler 293 / 949
  • Ticaret 33, (%100)

$cat = get_the_terms($post->cat_ID, 'product_cat');
$catID = $cat[0]->term_id;

if($catID == 98):
wc_get_template_part( 'content', 'single-product' );
else:
wc_get_template_part( 'content', 'single-product-custom' );
endif;
?>


Bu şekilde yaparsanız olacaktır. Yalnız birden fazla kategori varsa id olarak ilk kategorininkini alır.
 

 

MustafaZahit MustafaZahit WM Aracı Kullanıcı
  • Üyelik 27.06.2018
  • Yaş/Cinsiyet 30 / E
  • Meslek Öğrenci
  • Konum Mersin
  • Ad Soyad Z** Z**
  • Mesajlar 307
  • Beğeniler 15 / 32
  • Ticaret 0, (%0)

bilimokur adlı üyeden alıntı


$cat = get_the_terms($post->cat_ID, 'product_cat');
$catID = $cat[0]->term_id;

if($catID == 98):
wc_get_template_part( 'content', 'single-product' );
else:
wc_get_template_part( 'content', 'single-product-custom' );
endif;
?>


Bu şekilde yaparsanız olacaktır. Yalnız birden fazla kategori varsa id olarak ilk kategorininkini alır.



Hocam bu dediğiniz kodu aynen ekledim iki farklı yere ekledim ama olmadı eklediğim yerler
1- Sayfanın en üstüne eklediğim zaman kategori ID'si 98 olan ürün sayfası hiç açılmadı ama diğer kategori ürünleri normal şekilde açıldı,
2- bu kottan sonra eklediğim zaman kategori ID'si 98 olan ürün sayfası açıldı fakat bu seferde üstte dediğim gibi iki tane üst üste gözükmeye başladı ve ilk woocemmerece tasarımı sayfanın en üstüne oturdu, diğer ürünler normal açıldı,
sizde çalışıyor mu bu kodlar bende mi bir problem var anlamadım kaç gündür denemediğim yöntem kalmadı :/
 

 

MustafaZahit MustafaZahit WM Aracı Kullanıcı
  • Üyelik 27.06.2018
  • Yaş/Cinsiyet 30 / E
  • Meslek Öğrenci
  • Konum Mersin
  • Ad Soyad Z** Z**
  • Mesajlar 307
  • Beğeniler 15 / 32
  • Ticaret 0, (%0)
single-product.php bu şekilde hocam sizin verdiğiniz kodları eklediğim hali

/**
* The Template for displaying all single products
*
* This template can be overridden by copying it to yourtheme/woocommerce/single-product.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates
* @version 1.6.4
*/

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}

get_header( 'shop' ); ?>


$cat = get_the_terms($post->cat_ID, 'product_cat');
$catID = $cat[0]->term_id;

if($catID == 98):
wc_get_template_part( 'content', 'single-product' );
else:
wc_get_template_part( 'content', 'single-product-custom' );
endif;
?>







/**
* woocommerce_before_single_product hook.
*
* @hooked wc_print_notices - 10
*/
do_action( 'woocommerce_before_single_product' );

if ( post_password_required() ) {
echo get_the_password_form();
return;
}
?>

























Açıklama


$trimmed_content = wp_trim_words( $mycontent , 67, '' ); ?>






















/**
* woocommerce_after_main_content hook.
*
* @hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content)
*/
do_action( 'woocommerce_after_main_content' );
?>



 

 

MustafaZahit MustafaZahit WM Aracı Kullanıcı
  • Üyelik 27.06.2018
  • Yaş/Cinsiyet 30 / E
  • Meslek Öğrenci
  • Konum Mersin
  • Ad Soyad Z** Z**
  • Mesajlar 307
  • Beğeniler 15 / 32
  • Ticaret 0, (%0)
Yeni bir klasör oluşturmam gerekiyor mu acaba ? single-product-custom şeklinde?
 

 

wpuzman wpuzman WordPress Developer Kullanıcı
  • Üyelik 13.01.2017
  • Yaş/Cinsiyet 32 / E
  • Meslek Yazılım
  • Konum Trabzon
  • Ad Soyad B** M**
  • Mesajlar 2773
  • Beğeniler 293 / 949
  • Ticaret 33, (%100)
Orjinal şablonu değiştirmişsiniz çünkü. O yüzden çalışmıyor. single-product.php komple aşağıdaki gibi olacak.


/**
* The Template for displaying all single products
*
* This template can be overridden by copying it to yourtheme/woocommerce/single-product.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates
* @version 1.6.4
*/

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}

get_header( 'shop' ); ?>

/**
* woocommerce_before_main_content hook.
*
* @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
* @hooked woocommerce_breadcrumb - 20
*/
do_action( 'woocommerce_before_main_content' );
?>



$cat = get_the_terms($post->cat_ID, 'product_cat');
$catID = $cat[0]->term_id;

if($catID == 98):
wc_get_template_part( 'content', 'single-product' );
else:
wc_get_template_part( 'content', 'single-product-custom' );
endif;
?>



/**
* woocommerce_after_main_content hook.
*
* @hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content)
*/
do_action( 'woocommerce_after_main_content' );
?>

/**
* woocommerce_sidebar hook.
*
* @hooked woocommerce_get_sidebar - 10
*/
//do_action( 'woocommerce_sidebar' );
?>


/* Omit closing PHP tag at the end of PHP files to avoid "headers already sent" issues. */



do_action ve while döngüsüne dikkat ederek tekrar düzenleyin şablonunuzu. Ayrıca sizin için kontrol ettim. Düzgün çalışıyor.
 

 

wmaraci
Konuyu toplam 1 kişi okuyor. (0 kullanıcı ve 1 misafir)
Site Ayarları
  • Tema Seçeneği
  • Site Sesleri
  • Bildirimler
  • Özel Mesaj Al