สอบถามทำยังไงให้อยู่บรรทัดเดียวกัน

ถามตอบ ปัญหาการพัฒนา Extension ไม่ว่าจะเป็น Module plugin Component หรือ แม้แต่ template การปรับแต่งโค้ด Joomla ต่างๆ ทุกเวอร์ชั่น 1.5 2.5 หรือ 3.x

Moderator: mindphp, ผู้ดูแลกระดาน

ภาพประจำตัวสมาชิก
Thanapoom1514
PHP VIP Members
PHP VIP Members
โพสต์: 4329
ลงทะเบียนเมื่อ: 04/07/2022 9:46 am

สอบถามทำยังไงให้อยู่บรรทัดเดียวกัน

โพสต์ที่ยังไม่ได้อ่าน โดย Thanapoom1514 »

พอดีผมกำลังปลั๊กอิน Google Structured ใน description มันลงบรรทัดใหม่ครับ อยากให้มันอยู่บรรทัดเดียวกันครับ ต้องแก้ยังไงหรอครับ

ผลลัพธ์ที่ได้

โค้ด: เลือกทั้งหมด

<script type="application/ld+json">
                {
                        "@context": "https://schema.org/",
                        "@type": "Product",
                        "name" : "น้ำ",
                        "image" : "https://upload.wikimedia.org/wikipedia/commons/thumb/4/41/Iceberg_with_hole_near_Sandersons_Hope_2007-07-28_2.jpg/220px-Iceberg_with_hole_near_Sandersons_Hope_2007-07-28_2.jpg&quot",
                        "description" : "
น้ำเป็นสารประกอบอนินทรีย์ที่โปร่งใส ไม่มีรส ไม่มีกลิ่น",
                        "review": {
                            "@type": "Review",
                            "reviewRating": {
                              "@type": "Rating",
                              "ratingValue": "2.0",
                              "ratingCount": "1"
                            },
                            "author": {
                              "@type": "Person",
                              "name": "admin"
                            }
                          },
                          "aggregateRating": {
                            "@type": "AggregateRating",
                            "ratingValue" : "2.0",
                          	"ratingCount" : "1"
                        }, 
                        "offers" : {
                            "@type": "Offer",
                            "url": "",
                            "price": "5",
                            "priceCurrency": "THB"
                        },
                        "brand": {
                            "@type": "Brand",
                            "name": "test"
                          }
                         

                }
                
                    </script>
Joomla Development-1.png
Joomla Development-1.png (82.22 KiB) Viewed 1185 times

โค้ดใน php

โค้ด: เลือกทั้งหมด

$description = $article->metadesc != "" ? substr(strip_tags($article->metadesc), 0, 160) : ($article->text != "" ? substr(strip_tags($article->text), 0, 160) : '');

$document->addScriptDeclaration('
                {
                        "@context": "https://schema.org/",
                        "@type": "Product",
                        "name" : "'.$name.'",
                        "image" : "'.$getimage.'",
                        "description" : "'.$description.'",
                        "review": {
                            "@type": "Review",
                            "reviewRating": {
                              "@type": "Rating",
                              "ratingValue": "'.$rating.'",
                              "ratingCount": "'.$rating_count.'"
                            },
                            "author": {
                              "@type": "Person",
                              "name": "'.$author.'"
                            }
                          },
                          "aggregateRating": {
                            "@type": "AggregateRating",
                            "ratingValue" : "'.$rating.'",
                          	"ratingCount" : "'.$rating_count.'"
                        }, 
                        "offers" : {
                            "@type": "Offer",
                            "url": "'.$link.'",
                            "price": "'.$price_product.'",
                            "priceCurrency": "THB"
                        },
                        "brand": {
                            "@type": "Brand",
                            "name": "'.$brand.'"
                          }
                         

                }
                
                    ', 'application/ld+json');
:gfb:
ภาพประจำตัวสมาชิก
tsukasaz
PHP VIP Members
PHP VIP Members
โพสต์: 21991
ลงทะเบียนเมื่อ: 18/04/2012 9:39 am

Re: สอบถามทำยังไงให้อยู่บรรทัดเดียวกัน

โพสต์ที่ยังไม่ได้อ่าน โดย tsukasaz »

อาจจะมีตัว \n ซ่อนอยู่ ให้ลองใช้คำสั่ง nl2br ที่ข้อความก่อน ค่อยตัด tags ออกครับ
The last bug isn't fixed until the last user is dead. (Sidney Markowitz, 1995)
ตอบกลับโพส

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 94