Good day, dear coding gurus.

I tried to implement the task myself, but my knowledge is clearly not enough. not a programmer :-(

In a single.php Wordpress template, I wanted to implement the following:

if the specific page is set to "arbitrary field" customcategory = Некая категория and customlink = exsample.ru\nekayakegoriya\ , then pick them up and output, and if they are not, then output the code of standard bread crumbs.

 <span class="archive-title"> <?php $customcat = get_post_meta($post->ID, "customcategory", true); if ($customcat) '<div class="block-crumbs" prefix:v="http://rdf.data-vocabulary.org/#"><span typeof="v:Breadcrumb"><a href="https://exsample.ru/" rel="v:url" property="v:title">Главная</a></span> » <span typeof="v:Breadcrumb"><a rel="v:url" property="v:title" href="https://'.$customlink.'">'.$customcategory.'</a></span> » <span class="current-crumbs"><?php the_title(); ?></span></div>' else crumbs_breadcrumbs_new(); ?> </span> 

Tell me, please, how to register the command correctly.

    1 answer 1

    Get page id:

     $id = get_queried_object_id(); 

    Check if there is data on this page in wp_postmeta and substitute:

     if(get_post_meta($id, "customcategory", true) && get_post_meta($id, "customlink", true)){ ?> '<div class="block-crumbs" prefix:v="http://rdf.data-vocabulary.org/#"><span typeof="v:Breadcrumb"><a href="https://exsample.ru/" rel="v:url" property="v:title">Главная</a></span> » <span typeof="v:Breadcrumb"><a rel="v:url" property="v:title" href="https://'.$customlink.'">'.$customcategory.'</a></span> » <span class="current-crumbs"><?php the_title(); ?></span></div>' <?php }else{ crumbs_breadcrumbs_new(); } 
    • Thank you for responding. Entered the code you cited: writes a syntax error :-( - UserUser-name
    • I did not open the tag there, corrected. - Kirill Korushkin
    • I still write a syntax error :-( I edited the original message with the question and attached what I entered. Where did I make a mistake? - UserUser-name
    • Are you using the ACF plugin? - Kirill Korushkin
    • No, I do not use anything like this. But just below I connect the sidebar with this command: <?php if ( is_single() ) { $sidebar = get_post_meta($post->ID, "sidebar", true); // левый сайдбар if ($sidebar) get_sidebar($sidebar); else get_sidebar('second'); } else get_sidebar('second'); // is_single() ?> <?php if ( is_single() ) { $sidebar = get_post_meta($post->ID, "sidebar", true); // левый сайдбар if ($sidebar) get_sidebar($sidebar); else get_sidebar('second'); } else get_sidebar('second'); // is_single() ?> <?php if ( is_single() ) { $sidebar = get_post_meta($post->ID, "sidebar", true); // левый сайдбар if ($sidebar) get_sidebar($sidebar); else get_sidebar('second'); } else get_sidebar('second'); // is_single() ?> - UserUser-name