WordPress

Jak dodać metadane mojej strony z pojedynczym postem do mojej kolumny postów bez zmiany szablonu lub wtyczki w motywie phlox pro?

  • 1 marca, 2023
  • 15 min read
Jak dodać metadane mojej strony z pojedynczym postem do mojej kolumny postów bez zmiany szablonu lub wtyczki w motywie phlox pro?


Używam Phlox-pro z motywem rozwiązań biznesowych. (webhost ionos, jeśli to też ważne) Tworzę stronę internetową dla mojego sklepu surfingowego i używam kolumny postów, która jest dołączona do motywu, a także korzysta z wbudowanej wtyczki floksowej „auxin- portfolio”, aby wyświetlić moje kursy. istnieją poważne opcje rzeczy do wyświetlenia w kolumnie postów, które odnoszą się do strony z pojedynczym postem. np. tytuł, zdjęcie i inne rzeczy. To, czego mi brakuje, to metadata (w moim przypadku cena i czas kursu), dla mnie ważne jest, aby była wyświetlana w kolumnie postów już nie tylko na pojedynczej stronie postu. Moim pierwszym pomysłem było po prostu umieszczenie losowych przycisków lub pól tekstowych nad kolumną i umieszczenie ich nad pokazanymi postami, ale ponieważ szablon można edytować tylko jako całość, a nie konkretnie posty, nie mogę ich powiązać z postami, co powoduje ogromne problemy dotyczące różnych rozmiarów ekranu (wersja mobilna / tabletowa), więc moje jedyne pomysły na rozwiązanie problemu to:

  1. w jakiś sposób powiąż przyciski z identyfikatorami postów w kolumnie postów, aby lokalizacja była ustalona dla postów.

Lub

  1. użyj tej samej metody, której używa kolumna postu, aby uzyskać obraz tytułowy, np. aby pobrać obiekty metadanych i wyświetlić je w kolumnie.

Odniosę się do post-single-page/post-column, ale może to być również znane jako pojedyncza strona portfolio/siatka portfolio, o ile dobrze zrozumiałem. tylko dla wyjaśnienia, myślę, że to jest to samo w mojej sytuacji. niestety nie nadaję się do kodowania, ponieważ jest to również moja pierwsza strona internetowa i jestem całkiem nowy w całej sytuacji, dużo próbowałem z chatgpt, ale bez pełnego zrozumienia kodu i tego, jak wszystko działa, ai nie może mi naprawdę pomóc. .. może ktoś tutaj może 🙂 Ponieważ jest to moje pierwsze pytanie w stack overfolw/stackexchange, jeśli moje pytanie nie jest jasne lub niewystarczająco określone lub coś jest nie tak, proszę dać mi znać, co zmienić/jak poprawić/jak być bardziej jasne.

Umieszczę kod tego, co moim zdaniem jest odpowiedzialne za stronę pojedynczego postu (single-post.php) i kolumnę postów (post-column.php)

<?php global $post;

    $post_vars = auxin_get_post_format_media(
        $post,
        array(
            'request_from'       => 'single',
            'image_from_content' => false,
            'media_size'         => auxin_get_option( 'post_single_image_size', '' ),
            'crop'               => auxin_is_true( auxin_get_option( 'post_single_image_keep_aspect_ratio', false ) ) ? false : true,
        )
    );

    extract( $post_vars );

    // Get the alignment of the title in page content
    if( 'default' === $title_alignment = auxin_get_post_meta( $post, 'page_content_title_alignment', 'default' ) ){
        $title_alignment = auxin_get_option( 'post_single_title_alignment' );
    }
    $title_alignment="default" === $title_alignment ? '' : 'aux-text-align-' .$title_alignment;


    if( 'default' === $post_content_style = auxin_get_post_meta( $post, 'post_content_style', 'default' ) ){
        $post_content_style = auxin_get_option( 'post_single_content_style' );
    }
    $post_extra_classes = $post_content_style ? 'aux-'. esc_attr( $post_content_style ) .'-context' : '';

    // Whether to display post meta info or not
    if( 'default' === $show_post_meta_info = auxin_get_post_meta( $post, 'aux_post_info_show', true ) ){
        $show_post_meta_info = auxin_get_option( 'show_post_single_meta_info' );
    }
    $show_post_meta_info = auxin_is_true( $show_post_meta_info );

    // Whether the title bar is enabled or not
    if ( 'default' === $show_titlebar = auxin_get_post_meta( $post, 'aux_title_bar_show', "default" ) ) {
        $show_titlebar = auxin_get_option( $post->post_type . '_title_bar_show' );
    }
    // Use H1 for entry title if title bar is disabled
    $entry_title_tag = auxin_is_true( $show_titlebar ) ? 'h2' : 'h1';

?>
                                    <article <?php post_class( $post_extra_classes ); ?> >

                                            <?php if ( $has_attach ) : ?>
                                            <div class="entry-media">
                                                <?php echo $the_media; ?>
                                            </div>
                                            <?php endif; ?>
                                            <div class="entry-main">

                                                <header class="entry-header <?php echo esc_attr( $title_alignment ); ?>">
                                                <?php
                                                    if( 'quote' == $post_format ) {
                                                        echo '<p class="quote-format-excerpt">'. $excerpt .'</p>';
                                                    }

                                                    printf( '<%s class="entry-title %s">', $entry_title_tag, ( $show_title ? '' : ' aux-visually-hide' ) );

                                                        $post_title = !empty( $the_name ) ? esc_html( $the_name ) : get_the_title();

                                                        if( ! empty( $the_link ) ){
                                                            echo '<cite><a href="'.esc_url( $the_link ).'" title="'.esc_attr( $post_title ).'">'.$post_title.'</a></cite>';
                                                        } else {
                                                            echo $post_title;
                                                        }

                                                        if( "link" == $post_format ){ echo '<br/><cite><a href="'.esc_url( $the_link ).'" title="'.esc_attr( $post_title ).'">'.$the_link.'</a></cite>'; }

                                                    printf( '</%s>', $entry_title_tag );
                                                ?>
                                                    <div class="entry-format">
                                                        <div class="post-format"> </div>
                                                    </div>
                                                </header>

                                                <?php
                                                if( $show_post_meta_info || is_customize_preview() ){
                                                ?>
                                                <div class="entry-info <?php echo esc_attr( $title_alignment ); ?>">
                                                    <?php
                                                    if ( auxin_get_option( 'post_meta_date_show', true ) ) {
                                                    ?>
                                                    <div class="entry-date"><time datetime="<?php echo esc_attr( get_the_date( DATE_W3C ) ); ?>" ><?php echo get_the_date(); ?></time></div>
                                                    <?php }
                                                    if ( auxin_get_option( 'post_meta_author_show', true ) ) {
                                                    ?>
                                                    <div class="entry-author">
                                                        <span class="meta-sep"><?php esc_html_e("by", 'phlox-pro'); ?></span>
                                                        <span class="author vcard">
                                                            <a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" rel="author" title="<?php echo esc_attr( sprintf( __( 'View all posts by %s', 'phlox-pro'), get_the_author() ) ); ?>" >
                                                                <?php the_author(); ?>
                                                            </a>
                                                        </span>
                                                    </div>
                                                    <?php }
                                                    if ( auxin_get_option( 'post_meta_comments_show', true ) ) {
                                                    ?>
                                                    <div class="entry-comments">
                                                        <span class="meta-sep"><?php esc_html_e("with", 'phlox-pro'); ?></span>
                                                        <span class="meta-comment"><?php comments_number( __('no comment', 'phlox-pro'), __('one comment', 'phlox-pro'), __('% comments', 'phlox-pro') );?></span>
                                                    </div>
                                                    <?php }
                                                    if ( auxin_get_option( 'post_meta_categories_show', true ) ) {
                                                    ?>
                                                    <div class="entry-tax">
                                                        <?php // the_category(' '); we can use this template tag, but customizable way is needed! ?>
                                                        <?php $tax_name="category";
                                                              if( ( $cat_terms = wp_get_post_terms( $post->ID, $tax_name ) ) && ! is_wp_error( $cat_terms ) ){
                                                                  foreach( $cat_terms as $term ){
                                                                      echo '<a href="'. get_term_link( $term->slug, $tax_name ) .'" title="'.esc_attr__("View all posts in ", 'phlox-pro'). esc_attr( $term->name ) .'" rel="category" >'. esc_html( $term->name ) .'</a>';
                                                                  }
                                                              }
                                                        ?>
                                                    </div>
                                                    <?php }
                                                        edit_post_link(__("Edit", 'phlox-pro'), '<div class="entry-edit">', '</div>', null, 'aux-post-edit-link');

                                                        if( ( auxin_get_option( 'show_blog_post_like_button', 1 ) && 'top' === auxin_get_option( 'blog_post_like_button_position', 'top' ) ) || is_customize_preview() ){
                                                            if( function_exists('wp_ulike') ){
                                                                add_filter( 'wp_ulike_add_templates_args', 'auxin_change_like_icon', 1, 1);
                                                                wp_ulike( 'get', array( 'style' => 'wpulike-heart', 'button_type' => 'image', 'wrapper_class' => 'aux-wpulike aux-wpulike-single' ) );
                                                                remove_filter( 'wp_ulike_add_templates_args', 'auxin_change_like_icon', 1 );
                                                            }
                                                        }
                                                    ?>
                                                </div>
                                                <?php
                                                }
                                                ?>

                                                <div class="entry-content">
                                                    <?php if( 'quote' == $post_format ) {
                                                        echo $the_attach;
                                                    } else {
                                                        the_content( __( 'Continue reading', 'phlox-pro') );
                                                        // clear the floated elements at the end of content
                                                        echo '<div class="clear"></div>';
                                                        // create pagination for page content
                                                        wp_link_pages( array( 'before' => '<div class="page-links"><span>' . esc_html__( 'Pages:', 'phlox-pro') .'</span>', 'after' => '</div>' ) );
                                                    } ?>
                                                </div>

                                                <?php
                                                $show_share_links = auxin_get_option( 'show_post_single_tags_section', true );
                                                $the_tags         = get_the_tag_list('<span>'. esc_html__("Tags: ", 'phlox-pro'). '</span>', '<i>, </i>', '');

                                                if( $show_share_links ){
                                                ?>
                                                <footer class="entry-meta">
                                                <?php $share_icon = auxin_get_option( 'blog_post_share_button_icon', 'auxicon-share' ) ; ?>
                                                <?php if( $show_share_links && defined( 'AUXELS' ) ){ ?>
                                                        <div class="aux-post-share">
                                                            <div class="aux-tooltip-socials aux-tooltip-dark aux-socials aux-icon-left aux-medium">
                                                                <span class="aux-icon <?php echo esc_attr( $share_icon ); ?>"></span>
                                                                <span class="aux-text"><?php esc_html_e( 'Share', 'phlox-pro' ); ?></span>
                                                            </div>
                                                        </div>
                                                <?php } if( $the_tags ){ ?>
                                                        <div class="entry-tax">
                                                            <?php echo $the_tags; ?>
                                                        </div>
                                                <?php } else { ?>
                                                        <div class="entry-tax"><span><?php esc_html_e("Tags: No tags", 'phlox-pro' ); ?></span></div>
                                                    <?php }
                                                    if ( auxin_get_option( 'show_blog_post_share_button', false ) ) {
                                                        $data_text = ( 'text' === $share_type = auxin_get_option( 'blog_post_share_button_type', 'icon' ) ) ? 'data-text="' . esc_attr__( 'Share', 'phlox-pro' ) . '"' : '';
                                                        $icon_class = ( $share_type == 'text' ) ? 'aux-has-text' : 'aux-icon ' . $share_icon;
                                                    ?>
                                                        <div class="aux-single-post-share">
                                                             <div class="aux-tooltip-socials aux-tooltip-dark aux-socials aux-icon-left aux-medium aux-tooltip-social-no-text" <?php echo $data_text; ?> >
                                                                 <span class="<?php echo esc_attr( $icon_class ); ?>" <?php echo $data_text;?>></span>
                                                             </div>
                                                         </div>
                                                    <?php }
                                                    if ( auxin_get_option( 'show_blog_post_like_button', 1 ) && 'bottom' === auxin_get_option( 'blog_post_like_button_position', 'top' ) ) {
                                                        if ( function_exists( 'wp_ulike' ) ) {
                                                            add_filter( 'wp_ulike_add_templates_args', 'auxin_change_like_icon', 1, 1 );
                                                            wp_ulike( 'get', array( 'style' => 'wpulike-heart', 'button_type' => 'image', 'wrapper_class' => 'aux-wpulike aux-wpulike-single' ) );
                                                            remove_filter( 'wp_ulike_add_templates_args', 'auxin_change_like_icon', 1 );
                                                        }
                                                    }
                                                    ?>

                                                </footer>
                                                <?php } ?>
                                            </div>


                                            <?php // get related posts
                                            if( auxin_is_true( auxin_get_option('show_post_single_next_prev_nav') ) ){

                                                auxin_single_page_navigation( array(
                                                    'prev_text'      => esc_html__( 'Previous Post', 'phlox-pro' ),
                                                    'next_text'      => esc_html__( 'Next Post'    , 'phlox-pro' ),
                                                    'taxonomy'       => 'category',
                                                    'skin'           => esc_attr( auxin_get_option( 'post_single_next_prev_nav_skin' ) ) // minimal, thumb-no-arrow, thumb-arrow, boxed-image
                                                ));

                                            }

                                            if( function_exists( 'rp4wp_children' ) ){
                                                echo '<div class="aux-related-posts-container">' . rp4wp_children( false, false ) . '</div>';
                                            }
                                            ?>


                                            <?php if( auxin_get_option( 'show_blog_author_section', 1 ) ) { ?>
                                            <div class="entry-author-info">
                                                    <div class="author-avatar">
                                                        <?php echo get_avatar( get_the_author_meta("user_email"), 100 ); ?>
                                                    </div><!-- #author-avatar -->
                                                    <div class="author-description">
                                                        <dl>
                                                            <dt>
                                                                <a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" rel="author" title="<?php echo esc_attr( sprintf( __( 'View all posts by %s', 'phlox-pro'), get_the_author() ) ); ?>" >
                                                                    <?php the_author(); ?>
                                                                </a>
                                                            </dt>
                                                            <dd>
                                                            <?php if( get_the_author_meta('skills') ) { ?>
                                                                <span><?php the_author_meta('skills');?></span>
                                                            <?php }
                                                            if( auxin_get_option( 'show_blog_author_section_text' ) && ( get_the_author_meta('user_description') ) ) {
                                                                ?>
                                                                <p><?php the_author_meta('user_description');?>.</p>
                                                                <?php } ?>
                                                            </dd>
                                                        </dl>
                                                        <?php if( auxin_get_option( 'show_blog_author_section_social' ) ) {
                                                            auxin_the_socials( array(
                                                                'css_class' => ' aux-author-socials',
                                                                'size'      => 'medium',
                                                                'direction' => 'horizontal',
                                                                'social_list'   => array(
                                                                    'facebook'   => get_the_author_meta('facebook'),
                                                                    'twitter'    => get_the_author_meta('twitter'),
                                                                    'googleplus' => get_the_author_meta('googleplus'),
                                                                    'flickr'     => get_the_author_meta('flickr'),
                                                                    'dribbble'   => get_the_author_meta('dribbble'),
                                                                    'delicious'  => get_the_author_meta('delicious'),
                                                                    'pinterest'  => get_the_author_meta('pinterest'),
                                                                    'github'     => get_the_author_meta('github')
                                                                ),
                                                                'social_list_type'   => 'site',
                                                                'fill_social_values' => false
                                                            ));
                                                        }
                                                        ?>
                                                    </div><!-- #author-description -->

                                            </div> <!-- #entry-author-info -->
                                            <?php } ?>

                                       </article>

                        <article <?php post_class( $post_classes ); ?>>
                            <?php if ( $has_attach && $show_media ) { ?>
                            <div class="entry-media"><?php echo $the_media; ?></div>
                            <?php } ?>

                            <div class="entry-main">
                            <?php
                                $taxonomy_name    = ! isset( $taxonomy_name    ) ? 'category' : $taxonomy_name;
                                $max_taxonomy_num = empty( $max_taxonomy_num ) ? 3 : $max_taxonomy_num;
                                $cat_terms        = wp_get_post_terms( $post->ID, $taxonomy_name );
                                $featured_color   = get_post_meta( $post->ID, 'auxin_featured_color_enabled', true ) ? get_post_meta( $post->ID, 'auxin_featured_color', true ) : auxin_get_option( 'post_single_featured_color' );
                            ?>
                            <?php ob_start(); ?>

                                <header class="entry-header">
                                <?php
                                if( auxin_is_true(  $display_title ) || 'quote' == $post_format) {
                                    if( 'quote' == $post_format ) { echo '<p class="quote-format-excerpt">'. $excerpt .'</p>'; } ?>

                                    <h4 class="entry-title">
                                        <a href="<?php echo !empty( $the_link ) ? esc_url( $the_link ) : esc_url( get_permalink() ); ?>">
                                            <?php
                                                $the_name = ! empty( $the_name ) ? $the_name : get_the_title();
                                                echo empty( $words_num ) ? $the_name : wp_trim_words( $the_name, $words_num );
                                            ?>
                                        </a>
                                    </h4>
                                <?php
                                } ?>
                                    <div class="entry-format">
                                        <a href="<?php the_permalink(); ?>">
                                            <div class="post-format format-<?php echo esc_attr( $post_format ); ?>"> </div>
                                        </a>
                                    </div>
                                </header>
                            <?php
                            $entry_header = ob_get_clean();

                            if ( empty( $post_info_position ) ) {
                                $post_info_position = 'after-title';
                            }

                            // print entry-header before entry-info if post info position was set to 'before-title'
                            echo 'after-title' == $post_info_position ? $entry_header : '';

                            if( 'quote' !== $post_format && auxin_is_true( $show_info ) ) {
                                $show_date = ! isset( $show_date ) ? true : $show_date;
                            ?>
                                <?php if ( ! empty( $cat_terms ) && isset( $show_badge ) && auxin_is_true( $show_badge ) ) { ?>
                                    <span class="entry-badge aux-featured-color" data-featured-color="<?php echo !empty( $featured_color ) ? esc_html( $featured_color ) : ''; ?>">
                                        <a href="<?php the_permalink(); ?>"><?php echo esc_html( $cat_terms[0]->name ); ?></a>
                                    </span>
                                <?php } ?>

                                <div class="entry-info">
                                <?php if( auxin_is_true( $show_date ) ){ ?>
                                    <div class="entry-date">
                                        <a href="<?php the_permalink(); ?>">
                                            <time datetime="<?php echo esc_attr( get_the_date( DATE_W3C ) ); ?>" title="<?php echo esc_attr( get_the_date( DATE_W3C ) ); ?>" ><?php echo get_the_date(); ?></time>
                                        </a>
                                    </div>

                                <?php } ?>
                                <?php if ( isset( $display_author_header ) && auxin_is_true( $display_author_header ) ) { ?>
                                    <span class="entry-meta-sep meta-sep"><?php esc_html_e("by", 'phlox-pro'); ?></span>
                                    <span class="author vcard">
                                        <a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" rel="author" title="<?php echo esc_attr( sprintf( __( 'View all posts by %s', 'phlox-pro'), get_the_author() ) ); ?>" >
                                            <?php the_author(); ?>
                                        </a>
                                    </span>
                                <?php } ?>
                                <?php if ( auxin_is_true(  $display_categories ) ) {
                                    $tax_class_name = ! auxin_is_true( $show_date ) ? 'aux-no-sep' : '';
                                ?>
                                    <span class="entry-tax <?php echo esc_attr( $tax_class_name ); ?>">
                                        <?php
                                            if( $cat_terms ){

                                                foreach( $cat_terms as $index => $term ){
                                                    if( $index + 1 > $max_taxonomy_num ){
                                                       break;
                                                    }
                                                    if ( !is_wp_error( get_term_link( $term->slug, $taxonomy_name ) ) ) {
                                                        echo '<a href="'. get_term_link( $term->slug, $taxonomy_name ) .'" title="'.esc_attr__("View all posts in ", 'phlox-pro'). esc_attr( $term->name ) .'" rel="category" >'. esc_html( $term->name ) .'</a>';
                                                    }
                                                }
                                            }
                                        ?>
                                    </span>
                                    <?php } ?>
                                    <?php edit_post_link(__("Edit", 'phlox-pro'), '<i> | </i>', ''); ?>
                                    <?php if( 'video' === $post_format && ( isset( $show_format_icon ) && auxin_is_true( $show_format_icon ) )  ) { ?>
                                    <span class="entry-post-format aux-lightbox-video">
                                        <?php
                                            $get_video_url = get_post_meta( $post->ID, '_format_video_embed', true );
                                            if( ! empty( $get_video_url ) ){
                                                echo sprintf( '<a href="%s" class="aux-open-video aux-post-format-icon" data-type="video"><i class="auxicon-play-1" aria-hidden="true"></i></a>', $get_video_url);

*wyraźnie wolno mi tylko do 30k liter, więc drugi kod jest wycinany po linii 97 z 285 oczywiście mogę dostarczyć cały kod lub inne pliki, jeśli to konieczne

Warto przeczytać!  dostosowywanie - Niestandardowe dostosowywanie typu postu URl


Źródło