{"id":77314,"date":"2020-02-12T16:42:19","date_gmt":"2020-02-12T15:42:19","guid":{"rendered":"https:\/\/de.wordpress.org\/support\/topic\/custom-post-type-sidebar-anpassen-mit-advanced-custom-fields\/"},"modified":"2020-02-12T16:42:19","modified_gmt":"2020-02-12T15:42:19","slug":"custom-post-type-sidebar-anpassen-mit-advanced-custom-fields","status":"publish","type":"topic","link":"https:\/\/de.wordpress.org\/support\/topic\/custom-post-type-sidebar-anpassen-mit-advanced-custom-fields\/","title":{"rendered":"custom post type sidebar anpassen mit advanced custom fields"},"content":{"rendered":"<p>Hallo zusammen,<\/p>\n<p>ich habe eine WordPress Website, welche mit verschiedenen Post Types unsere Angebote darstellt. Es handelt sich um Eventprodukte bzw. Dienstleistungen &#8211; es sind also Produktseiten.<br \/>\nDiese Produktseiten verf\u00fcgen \u00fcber ein Sidebar Element, das mittels einer &#8222;posttype-entry.php&#8220; mit Infos zum Ablauf und Preis gef\u00fcllt wird. Die F\u00fcllung wird mittels des Plugins &#8222;Advanced Custom Fields&#8220; erreicht.<\/p>\n<p>Standardm\u00e4\u00dfig wird die Produktseite mit einem Preis und \/ oder einem Sonderpreis dargestellt. Die Preise k\u00f6nnen im Backend entsprechend eingegeben werden. Die entsprechenden Felder hei\u00dfen:<\/p>\n<p>preis_vor_angebot und preisklasse_1<\/p>\n<p>Dazu gibt es noch eine &#8222;posttype-header.php, die die klassen blur und preise regelt.<\/p>\n<p>Was wollte ich nun machen?<\/p>\n<p>Ich wollte zwei weitere Preise konfigurieren, habe auch weitere Felder angelegt im Plugin und alles soweit in die PHP eingegeben &#8211; dennnoch wirft WordPress mir einen Fehler vor. Ich w\u00fcrde mich freuen, wenn mir jemand dazu die Augen \u00f6ffnen kann.<\/p>\n<p>Die zus\u00e4tzlichen Felder hei\u00dfen dementsprechend:<\/p>\n<p>preis_vor_angebot_2 und preisklasse_2<\/p>\n<p>Hier die Codezeilen im originalen Zustand (ich habe die \u00fcbrigen 1.000 Zeilen weggelassen):<\/p>\n<p>Original Code-Teil der php Datei:<\/p>\n<pre><code> &lt;?php if ( get_field( &#039;preis_vor_angebot&#039; ) ): ?&gt;\n\n                                &lt;div class=&quot;vc_acf preis vc_txt_align_left blur&quot;&gt;ab &lt;span class=&quot;preise &lt;?php if( get_field(&#039;preis_vor_angebot&#039;) ): ?&gt;streich&lt;?php endif; ?&gt;&quot;&gt;&lt;?php the_field(&#039;preis_vor_angebot&#039;); ?&gt; \u20ac&lt;\/span&gt; p.P.&lt;\/div&gt;\n\n                                &lt;div class=&quot;vc_acf vc_txt_align_left&quot; style=&quot;background: #f2f0f0;padding: 12px 10px 8px;margin-bottom: 12px;font-size: 14px;font-weight: 600;font-family: &#039;Open Sans&#039;;margin-top: 16px;&quot;&gt;Deal:&lt;br&gt;\n                                &lt;span class=&quot;preis&quot;&gt;ab &lt;span class=&quot;preise&quot;&gt;&lt;?php the_field(&#039;preis_klasse_1&#039;); ?&gt; \u20ac&lt;\/span&gt; p.P.&lt;\/span&gt;&lt;\/div&gt;\n\n                                &lt;?php else: ?&gt;\n\n                                &lt;?php if( get_field(&#039;preis_klasse_1&#039;) ): ?&gt;\n                                  &lt;div class=&quot;vc_acf preis vc_txt_align_left&quot;&gt;ab &lt;span class=&quot;preise&quot;&gt;&lt;?php the_field(&#039;preis_klasse_1&#039;); ?&gt; \u20ac&lt;\/span&gt; p.P.&lt;\/div&gt;\n                                &lt;?php endif; ?&gt;\n&lt;?php endif; \/\/ end of if field_name logic ?&gt;<\/code><\/pre>\n<p><strong>Nun der modifizierte Code-Teil der php Datei:<\/strong><\/p>\n<pre><code> &lt;?php if ( get_field( &#039;preis_vor_angebot&#039; ) ): ?&gt;\n\n                                &lt;div class=&quot;vc_acf preis vc_txt_align_left blur&quot;&gt;ab &lt;span class=&quot;preise &lt;?php if( get_field(&#039;preis_vor_angebot&#039;) ): ?&gt;streich&lt;?php endif; ?&gt;&quot;&gt;&lt;?php the_field(&#039;preis_vor_angebot&#039;); ?&gt; \u00e2\u201a\u00ac&lt;\/span&gt; p.P.&lt;\/div&gt;\n\n                                &lt;div class=&quot;vc_acf vc_txt_align_left&quot; style=&quot;background: #f2f0f0;padding: 12px 10px 8px;margin-bottom: 12px;font-size: 14px;font-weight: 600;font-family: &#039;Open Sans&#039;;margin-top: 16px;&quot;&gt;Deal:&lt;br&gt;\n                                &lt;span class=&quot;preis&quot;&gt;ab &lt;span class=&quot;preise&quot;&gt;&lt;?php the_field(&#039;preis_klasse_1&#039;); ?&gt; \u00e2\u201a\u00ac&lt;\/span&gt; p.P.&lt;\/span&gt;&lt;\/div&gt;\n\n                                &lt;?php else: ?&gt;\n\n                                &lt;?php if( get_field(&#039;preis_klasse_1&#039;) ): ?&gt;\n                                  &lt;div class=&quot;vc_acf preis vc_txt_align_left&quot;&gt;ab &lt;span class=&quot;preise&quot;&gt;&lt;?php the_field(&#039;preis_klasse_1&#039;); ?&gt; \u00e2\u201a\u00ac&lt;\/span&gt; p.P.&lt;\/div&gt;\n                                &lt;?php endif; ?&gt;\n\n                                &lt;?php if ( get_field( &#039;preis_vor_angebot_2&#039; ) ): ?&gt;\n\n                                &lt;div class=&quot;vc_acf preis vc_txt_align_left blur&quot;&gt;ab &lt;span class=&quot;preise &lt;?php if( get_field(&#039;preis_vor_angebot_2&#039;) ): ?&gt;streich&lt;?php endif; ?&gt;&quot;&gt;&lt;?php the_field(&#039;preis_vor_angebot_2&#039;); ?&gt; \u00e2\u201a\u00ac&lt;\/span&gt; p.P.&lt;\/div&gt;\n\n                                &lt;div class=&quot;vc_acf vc_txt_align_left&quot; style=&quot;background: #f2f0f0;padding: 12px 10px 8px;margin-bottom: 12px;font-size: 14px;font-weight: 600;font-family: &#039;Open Sans&#039;;margin-top: 16px;&quot;&gt;Deal:&lt;br&gt;\n                                &lt;span class=&quot;preis&quot;&gt;ab &lt;span class=&quot;preise&quot;&gt;&lt;?php the_field(&#039;preis_klasse_2&#039;); ?&gt; \u00e2\u201a\u00ac&lt;\/span&gt; p.P.&lt;\/span&gt;&lt;\/div&gt;\n\n                                &lt;?php else: ?&gt;\n\n                                &lt;?php if( get_field(&#039;preis_klasse_2&#039;) ): ?&gt;\n                                  &lt;div class=&quot;vc_acf preis vc_txt_align_left&quot;&gt;ab &lt;span class=&quot;preise&quot;&gt;&lt;?php the_field(&#039;preis_klasse_2&#039;); ?&gt; \u00e2\u201a\u00ac&lt;\/span&gt; p.P.&lt;\/div&gt;\n                                &lt;?php endif; ?&gt;\n\n                                &lt;?php endif; \/\/ end of if field_name logic ?&gt;<\/code><\/pre>\n<p>Dazu gibt es wie o.g. die zugeh\u00f6rige header datei dieses post types, z.B. &#8222;posttype-header.php&#8220; genannt. In dieser war original dieser Eintrag:<\/p>\n<pre><code>&lt;?php if( get_field(&#039;preis_vor_angebot&#039;) ): ?&gt;\n&lt;style&gt;.streich { position: relative;color: #b4b4b4;}\n.streich::after {\n  content: &quot;&quot;;\n  display: block;\n  position: absolute;\n  bottom: 16px;\n  left: 0;\n  transform: skewY(-5deg);\n  width: 100%;\n  height: 3px;\n  background: #b95858;\n}<\/code><\/pre>\n<p>Und ich habe entsprechend des weiteren custom fields diesen hinzugef\u00fcgt:<\/p>\n<pre><code>&lt;?php if( get_field(&#039;preis_vor_angebot_2&#039;) ): ?&gt;\n&lt;style&gt;.streich { position: relative;color: #b4b4b4;}\n.streich::after {\n  content: &quot;&quot;;\n  display: block;\n  position: absolute;\n  bottom: 16px;\n  left: 0;\n  transform: skewY(-5deg);\n  width: 100%;\n  height: 3px;\n  background: #b95858;\n}<\/code><\/pre>\n<p>Ich w\u00fcrde mich sehr freuen, wenn mir jemand helfen k\u00f6nnte &#8211; auch eventuell k\u00f6nnte ich Euch dann die Dateien dazu mailen.<\/p>\n<p>Freue mich auf Eure Hilfe.<\/p>\n","protected":false},"template":"","class_list":["post-77314","topic","type-topic","status-publish","hentry","topic-tag-advanced-custom-fields","topic-tag-custom-post-type","topic-tag-sidebar"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/de.wordpress.org\/support\/wp-json\/wp\/v2\/topic\/77314","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/de.wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/de.wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/de.wordpress.org\/support\/wp-json\/wp\/v2\/topic\/77314\/revisions"}],"wp:attachment":[{"href":"https:\/\/de.wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=77314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}