• Resolved bearshang

    (@bearshang)


    Just now, I met something that made me confused

    I have customized a lot of post types for themes,

    E.g a and b

    in single.php,It only show an article content,i mean :
    when i open b post,He only shows the first article in a…

    I do not know if I understand it…

Viewing 10 replies - 1 through 10 (of 10 total)
  • Please share the single.php code in a gist at Github and link to it here so we can see the code. There is no way we can understand why only one article is loaded now. A link to the live site would help as well.

    Thread Starter bearshang

    (@bearshang)

    @rhand
    this is code

    
    <?php
    /**
     * The template for displaying all single posts
     *
     * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post
     *
     * @package WordPress
     * @subpackage Twenty_Seventeen
     * @since 1.0
     * @version 1.0
     */
    
    get_header(); ?>
    
        <div id="sub-header" class="layout-right-only has-background">
            <div class="meta-header" style="">
                <div class="limit-wrapper">
                    <div class="meta-header-inside">
                        <header class="page-header has-buttons">
                            <div class="page-header-content">
                                <h1 class="title"><?php the_title(); ?></h1>
                                <span class="post-siblings">
                                    <?php
                                    $previous_post = get_previous_post();
                                    $next_post = get_next_post();
    
                                    if ( !empty( $previous_post ) ) : ?>
                                        <a href="<?php echo esc_url( get_permalink( $previous_post->ID ) ); ?>" rel="prev"><span class="icon theme"></span></a>
                                    <?php
                                    endif; ?>
                                    <a href="/news/" class="all-items"><span class="icon shortcode theme" style=""></span></a>
                                    <?php
                                    if ( !empty( $next_post ) ) : ?>
                                    <a href="<?php echo esc_url( get_permalink( $next_post->ID ) ); ?>" rel="next"><span class="icon theme"></span></a>
                                    <?php endif; ?>
                                </span>
                            </div>
                        </header>
                    </div>
                </div>
            </div>
        </div>
    
        <div id="main" role="main" class="wpv-main boxed-layout">
            <div class="limit-wrapper">
                <div class="row page-wrapper">
    
                    <?php
                    /* Start the Loop */
                    while ( have_posts() ) : the_post(); ?>
    
                        <article id="post-<?php the_ID(); ?>" <?php post_class( 'single-post-wrapper  clearfix' ); ?>>
    
                            <?php get_sidebar(); ?>
    
                            <div class="page-content loop-wrapper">
                                <div class="post-content-outer single-post">
                                    <div class="entry-content">
                                        <?php the_content(); ?>
                                    </div>
                                </div>
                                <div class="clearboth">
                                    <div class="limit-wrapper">
                                        <div id="comments" class="comments-wrapper">
                                            <?php
                                            $fields =  array(
                                                'author' => '<div class="comment-form-comment form-input grid-1-1"><label for="author">Name</label><span class="required">*</span><input id="author" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required" name="author" type="text" placeholder="Name" required="required"/></div>',
                                                'email'  => '<div class="comment-form-author form-input grid-1-2"><label for="email">Email</label><span class="required">*</span><input id="email" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required" name="email" type="email" placeholder="E-mail" required="required"/></div>',
                                                'phone'  => '<div class="comment-form-email form-input grid-1-2"><div class="wpcf7-form-control-wrap"><input id="phone" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required" name="phone" type="text" placeholder="Phone" required="required"/></div></div>',
                                            );
                                            $comments_args = array(
                                                'title_reply' => '<h5 class="title">Write a guestbook:</h5>',
                                                'class_form' => 'single-form',
                                                'title_reply_before' => '',
                                                'comment_notes_before' => '',
                                                'fields' =>  $fields,
                                                'comment_field' => '<div class="comment-form-comment grid-1-1"><label for="comment">Message</label><textarea cols="40" rows="2" name="comment" type="textarea" placeholder="Your message..." required="required"></textarea></div>',
                                                'submit_field' => '<div class="grid-1-1">%1$s %2$s</div>',
                                                'class_submit' => 'submit',
                                                'label_submit' => 'SEND MESSAGE →'
                                            );
    
                                            comment_form( $comments_args );
                                            ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
    
                        </article><!-- #post-<?php the_ID(); ?> -->
    
                    <?php
                    endwhile; // End of the loop. ?>
    
                    <div class="c-recommend-service limit-wrapper">
                        <div class="row">
                            <?php
                            $c_comrom_services = new WP_Query( array(
                                'post_type' => 'service',
                                'post_per_page' => 4,
                                'posts_per_page' => 8,
                                'post_status' => 'publish'
                            ) );
                            while ( $c_comrom_services->have_posts() ) : $c_comrom_services->the_post();
                                ?>
                                <div class="wpv-grid grid-1-4">
                                    <a href="<?php the_permalink(); ?>" target="_blank">
                                        <div class="linkarea" style="min-height: 376px;">
                                            <div class="first">
                                                <?php the_post_thumbnail( 'custom-size-product', array( 'dh' => '150px' ) ); ?>
                                            </div>
                                            <div class="last"><h3 style="text-align: center;"><?php the_title(); ?></h3>
                                                <p style="text-align: center;"><?php echo mb_strimwidth( strip_tags( get_the_excerpt() ), '0', '60', '...' ); ?></p>
                                                <p style="text-align: center;">More »</p>
                                                <div class="push " style="height:10px"></div>
                                            </div>
                                        </div>
                                    </a>
                                </div>
                            <?php endwhile; wp_reset_postdata(); ?>
                        </div>
                    </div>
    
                </div>
            </div><!-- #main -->
        </div><!-- #primary -->
    
    <?php
        get_footer();
    
    
    Thread Starter bearshang

    (@bearshang)

    The Services page you link to is a post archive page, not a single.php or single post page. It has readmores to category pages. The category pages do not seem to load any posts, only another service. And only one. So it seems there may be an issue with loading other services on a category page, but I do not see issues on a particular single blog post page.

    Thread Starter bearshang

    (@bearshang)

    As you can see.
    http://csninsp.trueniu.com/service/
    http://csninsp.trueniu.com/training/
    http://csninsp.trueniu.com/video/
    http://csninsp.trueniu.com/industry/

    They are all page,in page.php, i use cuscom post type name as a query condition:

    
    <div id="main" role="main" class="wpv-main layout-full boxed-layout">
            <div class="row page-wrapper">
    
                <?php
                /**
                 * Loop the content
                 */
                while ( have_posts() ) : the_post(); ?>
    
                    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    
                        <div class="post-content">
    
                            <?php the_content(); ?>
    
                
                            <?php
                            /**
                             * Is front page for static page
                             */
                            global $post;
    
                            if ( is_page( 'industry' ) ) :
                                $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                                $industrys = new WP_Query( array(
                                    'post_type' => $post->post_name,
                                    'posts_per_page' => 16,
                                    'post_status' => 'publish',
                                    'paged' => $paged
                                ) ); ?>
                                <section class="portfolios normal industry-items">
                                    <ul class="clearfix fit-rows portfolio-items">
                                        <?php while ( $industrys->have_posts() ) : $industrys -> the_post();?>
                                            <li class="grid-1-4">
                                                <div class="portfolio-item-wrapper">
                                                    <div class="portfolio-image">
                                                        <div class="thumbnail">
                                                            <?php the_post_thumbnail( 'custom-size-industry', array( 'dh' => '303px' ) ); ?>
                                                        </div>
                                                    </div>
                                                    <div class="portfolio_details">
                                                        <a href="<?php the_permalink(); ?>" target="_blank">
                                                            <h3 class="title"><?php the_title(); ?></h3>
                                                            <div class="excerpt"><p>Learn More</p></div>
                                                        </a>
                                                    </div>
                                                </div>
                                            </li>
                                        <?php endwhile; wp_reset_postdata(); ?>
                                    </ul>
    
                                    <?php
                                    /**
                                     * The pagenation
                                     */
                                    $links = paginate_links( array(
                                        'current'            => max( 1, $paged ),
                                        'prev_text'          => __('«'),
                                        'next_text'          => __('»'),
                                        'total'              => $industrys->max_num_pages,   //WP_Query结果集中可以显示的最大页数
                                    ) );
                                    echo _navigation_markup( $links, 'pagination', 'screen_reader_text' ); ?>
    
                                </section>
                            <?php elseif ( is_page( 'video' ) ) :
                                $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                                $video_posts = new WP_Query( array(
                                    'post_type' => $post->post_name,
                                    'posts_per_page' => 16,
                                    'post_status' => 'publish',
                                    'paged' => $paged
                                ) );
                            ?>
                                <div class="limit-wrapper clearfix">
                                    <?php while ( $video_posts->have_posts() ) : $video_posts -> the_post(); ?>
                                    <div class="wpv-grid grid-1-3">
                                        <a href="<?php the_permalink(); ?>" target="_blank">
                                            <div class="linkarea">
                                                <div class="first">
                                                    <?php the_post_thumbnail( 'medium', array( 'dh' => '150px' ) ); ?>
                                                </div>
                                                <div class="last"><h3><?php the_title(); ?></h3>
                                                    <p><?php echo mb_strimwidth( strip_tags( get_the_excerpt() ), '0', '60', '...' ); ?></p>
                                                    <p>
                                                        <span class="fl"><i class="videos-icon-clock"></i> <?php echo get_the_date( 'Y-m-d' ); ?></span>
                                                        <span class="fr"><i class="videos-icon-eye"></i> <?php echo tn_get_record_visitors_num( '', '' ); ?></span>
                                                    </p>
                                                </div>
                                            </div>
                                        </a>
                                    </div>
                                    <?php
                                    endwhile;
                                    wp_reset_postdata();
                                    ?>
                                </div>
                                <?php
                                /**
                                 * The pagenation
                                 */
                                $links = paginate_links( array(
                                    'current'            => max( 1, $paged ),
                                    'prev_text'          => __('«'),
                                    'next_text'          => __('»'),
                                    'total'              => $video_posts->max_num_pages,   //WP_Query结果集中可以显示的最大页数
                                ) );
                                echo _navigation_markup( $links, 'pagination', 'screen_reader_text' );
    
                            else :
                                $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                                $custom_posts= new WP_Query( array(
                                'post_type' => $post->post_name,
                                'posts_per_page' => 16,
                                'post_status' => 'publish',
                                'paged' => $paged
                                ) );
                            ?>
                            <div class="limit-wrapper">
                            <?php while ( $custom_posts->have_posts() ) : $custom_posts-> the_post(); ?>
                                <div class="page-content">
                                    <div class="loop-wrapper regular">
                                        <div class="list-item">
                                            <div class="post-article">
                                                <div class="video-post-format">
                                                    <div class="post-row">
                                                        <div class="post-row-left">
                                                            <div class="post-date">
                                                                <span class="top-part"><?php echo get_the_date('d'); ?></span>
                                                                <span class="bottom-part"><?php echo get_the_date('m y'); ?></span>
                                                            </div>
                                                        </div>
                                                        <div class="post-row-center">
                                                            <?php
                                                            if ( has_post_thumbnail() ) :?>
                                                                <div class="post-media">
                                                                    <div class="media-inner">
                                                                        <?php the_post_thumbnail('custom-size-news', array('dh' => '160px')); ?>
                                                                    </div>
                                                                </div>
                                                            <?php endif; ?>
                                                            <div class="post-content-outer">
                                                                <header class="single">
                                                                    <div class="content">
                                                                        <h3>
                                                                            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                                                                        </h3>
                                                                    </div>
                                                                </header>
                                                                <div class="post-content the-content">
                                                                    <p><?php the_excerpt(); ?></p>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <?php
                                endwhile;
                                wp_reset_postdata();
    
                                /**
                                 * The pagenation
                                 */
                                $links = paginate_links( array(
                                    'current'            => max( 1, $paged ),
                                    'prev_text'          => __('«'),
                                    'next_text'          => __('»'),
                                    'total'              => $custom_posts->max_num_pages,   //WP_Query结果集中可以显示的最大页数
                                ) );
                                echo _navigation_markup( $links, 'pagination', 'screen_reader_text' );
    
                            endif;
                            ?>
                            </div>
                        </div><!-- .entry-content -->
    
                    </article><!-- #post-<?php the_ID(); ?> -->
    
                <?php endwhile; // End of the loop. ?>
    
            </div><!-- #main -->
        </div><!-- #primary -->
    

    But when I click on these custom Post type links to the detail page, he always shows me the same content in the development environment, and the problem is not happening.

    I do see 'post_type' => $post->post_name The part $post->post_name is used to get the name or slug of the post. And it will be the same here for all locations. Why do you not try using the actual post_type name? See https://developer.wordpress.org/reference/classes/wp_query/#post-type-parameters
    Example at SO:
    $query = new WP_Query( array( 'post_type' => 'job_posting' ) );

    • This reply was modified 8 years, 6 months ago by Rhand.
    Thread Starter bearshang

    (@bearshang)

    No,No,No

    I think I may not have to understand.

    i use 'post_type' => $post->post_name is corrects

    Because work in the page.php everything is normal, through WP_Query get to the corresponding article items.

    The only thing that is not normal is single.php, when I click on permalink in page.php, he shows the article on single.php is always the first one, it is strange

    Perhaps you need to share a permalink on one of the pages where it is loaded. On http://csninsp.trueniu.com/service/ I see in the source that it is a post archive as I can see by the added classes: class="archive post-type-archive post-type-archive-service So a custom post type service. A link there to “Construction and Engineering” goes to http://csninsp.trueniu.com/service/construction-engineering-service/. This is a single post for that custom post type. If there is no template for the single services CPT the single.php will be loaded. I guess that goes for all single CPT posts for all services. And that may be the problem as you want the CPT single post connected to the Custom Post Type. Perhaps you need to create some other single.php files for all the CPTs like single-services.php add the proper query to those. Either that or customize the query in single.php to load the proper post from CPT in question using if else

    Thread Starter bearshang

    (@bearshang)

    I found the reason that was caused by my negligence..

    Did you see the <? Php get_sidebar ();?> In single.php?

    Here, I developed a widget for getting custom post type.

    But at the end of the widgets code I did not use wp_reset_postdata ().

    Because of this, he always shows the first article, thank you very much for your reply

    happy code for everyday.

    The only thing that is not normal is single.php, when I click on permalink in page.php, he shows the article on single.php is always the first one, it is strange.

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘single.php Only show an article content?’ is closed to new replies.