ID von Custom Post herausfinden?

  • Hallo,

    ich möchte die single.php verändern, sodass Artikel, die in einer bestimmten Kategorie veröffentlich werden, anderes dargestellt werdeb. Das ist ja mit folgendem Befehl zunächst kein Problem:

    PHP
    <?php if(in_category('XX')) { ?>  ...  <?php } ?>

    Aber ich benutze ein Theme, in dem viel mit Custom Posts gearbeitet wird. Wie bekomme ich die Category-ID von Custom Posts heraus, damit ich diese Zuordung basteln kann?

    Gibt man unter Umständen einfach den gewählten Namen des Custom-Posts an? In meinem Fall wäre das dann

    PHP
    <?php if(in_category('foods')) { ?>  ...  <?php } ?>

    Link zu der Seite - Front-End des Custom Posts:
    http://fewo-wesemann.de/landhaus-wp/speisekarte/

    Single Post, der u.a. anders dargestellt werden soll:
    http://fewo-wesemann.de/landhaus-wp/foods/der-rheinlander/

    • Anzeige

    Hallo!

    Wenn du gerade an deiner Website arbeitest oder dein aktuelles Hosting überdenkst: Wir betreiben mit NetzLiving eine Hosting-Plattform, die speziell auf Performance, Sicherheit und einfache Verwaltung ausgelegt ist.

    • ✔️ Schnelle Ladezeiten (optimiert für WordPress & Co.)
    • ✔️ Deutsche Server & DSGVO-konform
    • ✔️ Persönlicher Support (kein 0815-Ticket-System)

    Mehr erfahren

  • Du kannst das auch einfacher haben (wenn ich Dich jetzt richtig verstanden habe).

    Zum beispiel, Du hast einen Custom Post Type "buecher" - lege in Deinem Theme einfach eine single-buecher.php an. Rufst Du einen jeweiligen Custom post Type auf, wird dieser so dargestellt, wie Du das in der "single-buecher.php" definiert hast.


    siehe auch: http://wordpress.org/support/topic/…ustom-post-type

    <?php if (have_read_this()) : while (have_read_this()) : read_it_again(); ?>

  • Da taucht aber die nächste Frage auf: Ich möchte spezifischen Einträge des Costum-Posts in diese single-custom.php übernehmen. Das gelingt mir aber nicht. Entweder die sepeziellen Angaben zu Preis oder Zusatzoptionen werden nicht übernommen - oder das Script loopt alle Einträge in dieser Custom-Category. Aber genau das will ich ja nicht.

    Es liegt daran, dass ich dieses Script nicht verstehe:
    [COLOR=#0000BB][FONT=monospace]<?php [/FONT][/COLOR][COLOR=#007700][FONT=monospace]if ([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]get_option[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'fl_menus_order'[/FONT][/COLOR][COLOR=#007700][FONT=monospace])==[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'Oldest First'[/FONT][/COLOR][COLOR=#007700][FONT=monospace]) : [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$loop [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= new [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]WP_Query[/FONT][/COLOR][COLOR=#007700][FONT=monospace](array([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'post_type' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]=> [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'foods'[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'posts_per_page' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]=> [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'-1'[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'order' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]=> [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'ASC'[/FONT][/COLOR][COLOR=#007700][FONT=monospace])); elseif ([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]get_option[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'fl_menus_order'[/FONT][/COLOR][COLOR=#007700][FONT=monospace])==[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'Alphabet'[/FONT][/COLOR][COLOR=#007700][FONT=monospace]) : [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$loop [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= new [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]WP_Query[/FONT][/COLOR][COLOR=#007700][FONT=monospace](array([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'post_type' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]=> [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'foods'[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'posts_per_page' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]=> [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'-1'[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'order' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]=> [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'ASC'[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'orderby' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]=> [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'title'[/FONT][/COLOR][COLOR=#007700][FONT=monospace])); else : [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$loop [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= new [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]WP_Query[/FONT][/COLOR][COLOR=#007700][FONT=monospace](array([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'post_type' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]=> [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'foods'[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'posts_per_page' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]=> [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'-1'[/FONT][/COLOR][COLOR=#007700][FONT=monospace])); endif; while ( [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$loop[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]have_posts[/FONT][/COLOR][COLOR=#007700][FONT=monospace]() ) : [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$loop[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]the_post[/FONT][/COLOR][COLOR=#007700][FONT=monospace](); [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$custom [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]get_post_custom[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$post[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]ID[/FONT][/COLOR][COLOR=#007700][FONT=monospace]); [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$price [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$custom[/FONT][/COLOR][COLOR=#007700][FONT=monospace][[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"price"[/FONT][/COLOR][COLOR=#007700][FONT=monospace]][[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]0[/FONT][/COLOR][COLOR=#007700][FONT=monospace]]; [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$additional_1 [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$custom[/FONT][/COLOR][COLOR=#007700][FONT=monospace][[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"additional_1"[/FONT][/COLOR][COLOR=#007700][FONT=monospace]][[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]0[/FONT][/COLOR][COLOR=#007700][FONT=monospace]]; [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$additional_price_1 [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$custom[/FONT][/COLOR][COLOR=#007700][FONT=monospace][[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"additional_price_1"[/FONT][/COLOR][COLOR=#007700][FONT=monospace]][[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]0[/FONT][/COLOR][COLOR=#007700][FONT=monospace]]; [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$additional_2 [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$custom[/FONT][/COLOR][COLOR=#007700][FONT=monospace][[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"additional_2"[/FONT][/COLOR][COLOR=#007700][FONT=monospace]][[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]0[/FONT][/COLOR][COLOR=#007700][FONT=monospace]]; [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$additional_price_2 [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$custom[/FONT][/COLOR][COLOR=#007700][FONT=monospace][[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"additional_price_2"[/FONT][/COLOR][COLOR=#007700][FONT=monospace]][[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]0[/FONT][/COLOR][COLOR=#007700][FONT=monospace]]; [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$additional_3 [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$custom[/FONT][/COLOR][COLOR=#007700][FONT=monospace][[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"additional_3"[/FONT][/COLOR][COLOR=#007700][FONT=monospace]][[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]0[/FONT][/COLOR][COLOR=#007700][FONT=monospace]]; [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$additional_price_3 [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$custom[/FONT][/COLOR][COLOR=#007700][FONT=monospace][[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"additional_price_3"[/FONT][/COLOR][COLOR=#007700][FONT=monospace]][[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]0[/FONT][/COLOR][COLOR=#007700][FONT=monospace]]; [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$src [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]wp_get_attachment_image_src[/FONT][/COLOR][COLOR=#007700][FONT=monospace]( [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]get_post_thumbnail_id[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$post[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]ID[/FONT][/COLOR][COLOR=#007700][FONT=monospace]), array( [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]650[/FONT][/COLOR][COLOR=#007700][FONT=monospace],[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]400 [/FONT][/COLOR][COLOR=#007700][FONT=monospace]), [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]false[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]); [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]?>[/FONT][/COLOR]

    Was muss ich ändern, bzw. wegnehmen, damit nicht mehr alle Angeben in dieser Custom-Kategorie geloopt werden. Ich möchte nur ein Produkt auf der Speisekarte mit den entsprechenden Infos präsentieren.

    Könnt ihr mir helfen?

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!