最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

posts - "read more" redirects to the wrong page

programmeradmin1浏览0评论

I would appreciate it if someone can help me out. I am having issues with my blog posts. I had someone customize by site but they made a mistake with the blog posts. I am no longer working with them.

ISSUE

I have three different pages that feature blogs (events, news, The Journal). Although the posts are posting initially to the correct pages, when you click "read more" for any of the posts, they all open on "The Journal" page. Ideally, I want each blog to appear and open on their individual pages. Below you can see the relevant php code (i think) for "single.php", "tag.php", "The Journal.php", "content-tag.php", "taxononomy-blog_category.php" . I would appreciate if someone can help me out. Thanking you in advance for any guidance, Mike

single.php

 * @package mywebsite
 */

get_header(); ?>

<div class = "container the journal">
<?php get_template_part('template-parts/header/page-header-all'); ?>

    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">

        <?php
        while ( have_posts() ) : the_post();

            get_template_part( 'template-parts/content', get_post_format() );

        endwhile; // End of the loop.
        ?>

        </main><!-- #main -->
    </div><!-- #primary -->
</div>

<?php
get_footer();

TAG TEMPLATE tag.php

<?php
/**
 * The template for displaying archive pages
 *
 * @link 
 *
 * @package my website 
 */

get_header(); ?>

  <style>
  .thumbnail img {
    max-height: 350px;
  }
  </style>
    <div id="primary" class="container content-area">
    <?php get_template_part('template-parts/header/page-header-all'); ?>

      <div class = "row journal-blog">
        <div class = "col-md-9" style = "margin-top: 50px;">
          <?php
            if ( have_posts() ) : ?>

            <?php $i = 0; ?>

                <?php
                /* Start the Loop */
                while ( have_posts() ) : the_post(); ?>
               <?php if ( $i % 2 == 0 ) { ?><div class="row"><?php } ?>
                 <div class="col-md-6 thumbnail">
                   <?php the_post_thumbnail( 'full', array( 'class'  => 'img-fluid' ) ); ?>
                   <h3><?php echo get_the_date(); ?></h3>
                   <h2 class = "thumbnail-title"><?php echo the_title(); ?></h2>
                   <h3 style = "padding-top: 0px; padding-bottom: 30px;"><a href = "<?php echo get_permalink(); ?>">Read More</a></h3>
                 </div>
            <?php $i++; ?>
            <?php if ( $i % 2 == 0 ) { ?></div><?php } ?>
                <?php endwhile;
            endif; ?>
          <?php wp_reset_query(); ?>
        </div>
        <? if ($i % 2 != 0) { ?></div><?php } ?>
        <div class = "col-md-3">
          <?php get_sidebar(); ?>
        </div>
      </div>
    </div><!-- #primary -->

<?php
get_footer();

<?php
/**
 * Template part for displaying posts
 *
 * @link 
 *
 * @package mywebsite
 */

?>
<div class = "container blog-post-container-mywebsite">
    <article id="post-<?php the_ID(); ?>" class = "blog-post-mywebsite"<?php post_class(); ?>>
        <header class="entry-header">
            <?php
            $my_date = the_date( '', '<h3>', '</h3>', false );
            echo $my_date;
            ?>
            <?php
            if ( is_single() ) :
                the_title( '<h1 class="entry-title">', '</h1>' );
            else :
                the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' );
            endif;
            ?>
        </header><!-- .entry-header -->


        <?php $images = get_field('slideshow'); ?>

        <?php if( $images ): ?>

            <div id="slider" class="flexslider">
            <ul class = "slides">
                <?php foreach( $images as $image ): ?>
                    <li>
                        <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
                    </li>
                <?php endforeach; ?>
            </ul>
            </div>

        <?php endif; ?>

            <?php if( get_field('video') ): ?>
                <div id="slider" class="flexslider">
                    <div class="video-fit">
                        <?php the_field(video); ?>
                    </div>
                </div>
            <?php endif; ?>

    <div class = "row" style = "padding: 32px 0;">
        <div class="col-md-4" style = "padding-left: 0px !important;">
            <?php if( get_field('address') ): ?>
                <h4>Address</h4>
                <?php the_field(address); ?>
            <?php endif; ?>

            <?php if( get_field('telephone') ): ?>
                <h4>Telephone</h4>
                <?php the_field(telephone); ?>
            <?php endif; ?>

                <?php if ( function_exists( 'ADDTOANY_SHARE_SAVE_KIT' ) ) {
                    ADDTOANY_SHARE_SAVE_KIT( array(
                        'buttons' => array( 'facebook', 'twitter', 'google_plus', 'pinterest', 'linkedin' ),
                    ) );
                } ?>
        </div>

        <div class = "col-md-8">
            <div>
                <?php if( get_field('blog_text') ): ?><?php the_field(blog_text); ?><?php endif; ?>
            </div>

        </div>
    </div>


    </article><!-- #post-## -->
</div>

THE JOURNAL TEMPLATE.php

<?php
/* Template Name: The Journal */
?>

<?php get_header(); ?>


<div class = “the journal">
  <?php get_template_part('template-parts/header/page-header-all'); ?>
  <div class = "row no-gutter the journal-blog">
    <div>
    <?php
      $args=array(
         'post_type' => 'post',
         'post_status' => 'publish',
         'orderby' => 'DESC'
      );

      $my_query = null;
      $my_query = new WP_Query($args);
    ?>

    <?php if (have_posts()) : ?>
      <?php while ($my_query->have_posts()) : $my_query->the_post();?>
        <?php if( $my_query->current_post == 0 && !is_paged() ) : ?>

          <div class = "row no-gutter" style = "padding-bottom: 32px;">
            <div class = "col-md-12" style="padding-left: 0px; padding-right: 0px;">
              <h2><?php echo the_title(); ?></h2>
              <a href="<?php echo esc_url( get_permalink() ); ?>"><?php the_post_thumbnail( 'full', array( 'class'  => 'img-fluid' ) ); ?></a>

              <div class = "row no-gutters" style = "padding: 32px 0;">
                    <div class = "col-md-4">
                        <h4><?php echo get_the_date(); ?></h4>
                    </div>
                    <div class="col-md-8"><?php $summary = get_field('blog_text');
                        echo substr($summary, 0, 300); ?>... <a href="<?php echo esc_url( get_permalink() ); ?>">Read More</a>
                    </div>
              </div>

            </div>
          </div>

        <?php endif; ?>

      <?php endwhile; ?>

      <?php
        $args=array(
           'post_type' => 'post',
           'post_status' => 'publish',
           'offset' => '1',
           'orderby' => 'DESC'
        );

        $my_query2 = null;
        $my_query2 = new WP_Query($args);
      ?>
        <?php $i = 0; ?>
      <?php while ($my_query2->have_posts()) : $my_query2->the_post();?>
        <?php if($i % 2 == 0) { ?>
            <div class="row">
                  <?php
                  }
                  ?>
              <div class="col-md-6 thumbnail">
                <a href="<?php echo esc_url( get_permalink() ); ?>"><?php the_post_thumbnail( 'full', array( 'class'  => 'img-fluid' ) ); ?></a>
                <h3><?php echo get_the_date(); ?></h3>
                <h2 class = "thumbnail-title"><?php echo the_title(); ?></h2>
                <h3 style = "padding-top: 0px; padding-bottom: 30px;"><a href = "<?php echo get_permalink(); ?>">Read More</a></h3>
              </div>
              <?php $i++; if($i % 2 == 0) { ?> </div><?php } ?>
     <?php endwhile; ?>
      <?php wp_reset_query(); ?>
    <?php endif; ?>
  </div>
  <? if ($i % 2 != 0) { ?></div><?php } ?>
  <div class = "col-md-3">
    <?php get_sidebar(); ?>
  </div>
  </div>
</div>
<?php get_footer(); ?>

content-tag.php

<?php
/**
 * Template part for displaying posts
 *
 * @link 
 *
 * @package mywebsite
 */

?>
<div class = "container blog-post-container-mywebsite">
  <h2><?php echo the_title(); ?></h2>
  <?php the_post_thumbnail( 'full', array( 'class'  => 'img-fluid' ) ); ?>
</div>

content-category.php

<?php
/**
 * Template part for displaying posts
 *
 * @link 
 *
 * @package mywebsite
 */

?>
<div class = "container blog-post-container-mywebsite">
  <h2><?php echo the_title(); ?></h2>
  <?php the_post_thumbnail( 'full', array( 'class'  => 'img-fluid' ) ); ?>
</div>

taxonomy-blog_category.php

<?php
/**
 * The template for displaying archive pages
 *
 * @link 
 *
 * @package mywebsite
 */

get_header(); ?>

  <style>
  .thumbnail img {
    max-height: 350px;
  }
  </style>
    <div id="primary" class="container content-area">
    <?php get_template_part('template-parts/header/page-header-all'); ?>

      <div class = "row journal-blog">
        <div style = "margin-top: 50px;">
          <?php
            if ( have_posts() ) : ?>

            <?php $i = 0; ?>

                <?php
                /* Start the Loop */
                while ( have_posts() ) : the_post(); ?>
               <?php if ( $i % 2 == 0 ) { ?><div class="row"><?php } ?>
                 <div class="col-md-6 thumbnail">
                   <?php the_post_thumbnail( 'full', array( 'class'  => 'img-fluid' ) ); ?>
                   <h3><?php echo get_the_date(); ?></h3>
                   <h2 class = "thumbnail-title"><?php echo the_title(); ?></h2>
                   <h3 style = "padding-top: 0px; padding-bottom: 30px;"><a href = "<?php echo get_permalink(); ?>">Read More</a></h3>
                 </div>
            <?php $i++; ?>
            <?php if ( $i % 2 == 0 ) { ?></div><?php } ?>
                <?php endwhile;
            endif; ?>
          <?php wp_reset_query(); ?>
        </div>
        <? if ($i % 2 != 0) { ?></div><?php } ?>
        <div class = "col-md-3">
          <?php get_sidebar(); ?>
        </div>
      </div>
    </div><!-- #primary -->

<?php
get_footer();

I would appreciate it if someone can help me out. I am having issues with my blog posts. I had someone customize by site but they made a mistake with the blog posts. I am no longer working with them.

ISSUE

I have three different pages that feature blogs (events, news, The Journal). Although the posts are posting initially to the correct pages, when you click "read more" for any of the posts, they all open on "The Journal" page. Ideally, I want each blog to appear and open on their individual pages. Below you can see the relevant php code (i think) for "single.php", "tag.php", "The Journal.php", "content-tag.php", "taxononomy-blog_category.php" . I would appreciate if someone can help me out. Thanking you in advance for any guidance, Mike

single.php

 * @package mywebsite
 */

get_header(); ?>

<div class = "container the journal">
<?php get_template_part('template-parts/header/page-header-all'); ?>

    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">

        <?php
        while ( have_posts() ) : the_post();

            get_template_part( 'template-parts/content', get_post_format() );

        endwhile; // End of the loop.
        ?>

        </main><!-- #main -->
    </div><!-- #primary -->
</div>

<?php
get_footer();

TAG TEMPLATE tag.php

<?php
/**
 * The template for displaying archive pages
 *
 * @link https://codex.wordpress/Template_Hierarchy
 *
 * @package my website 
 */

get_header(); ?>

  <style>
  .thumbnail img {
    max-height: 350px;
  }
  </style>
    <div id="primary" class="container content-area">
    <?php get_template_part('template-parts/header/page-header-all'); ?>

      <div class = "row journal-blog">
        <div class = "col-md-9" style = "margin-top: 50px;">
          <?php
            if ( have_posts() ) : ?>

            <?php $i = 0; ?>

                <?php
                /* Start the Loop */
                while ( have_posts() ) : the_post(); ?>
               <?php if ( $i % 2 == 0 ) { ?><div class="row"><?php } ?>
                 <div class="col-md-6 thumbnail">
                   <?php the_post_thumbnail( 'full', array( 'class'  => 'img-fluid' ) ); ?>
                   <h3><?php echo get_the_date(); ?></h3>
                   <h2 class = "thumbnail-title"><?php echo the_title(); ?></h2>
                   <h3 style = "padding-top: 0px; padding-bottom: 30px;"><a href = "<?php echo get_permalink(); ?>">Read More</a></h3>
                 </div>
            <?php $i++; ?>
            <?php if ( $i % 2 == 0 ) { ?></div><?php } ?>
                <?php endwhile;
            endif; ?>
          <?php wp_reset_query(); ?>
        </div>
        <? if ($i % 2 != 0) { ?></div><?php } ?>
        <div class = "col-md-3">
          <?php get_sidebar(); ?>
        </div>
      </div>
    </div><!-- #primary -->

<?php
get_footer();

<?php
/**
 * Template part for displaying posts
 *
 * @link https://codex.wordpress/Template_Hierarchy
 *
 * @package mywebsite
 */

?>
<div class = "container blog-post-container-mywebsite">
    <article id="post-<?php the_ID(); ?>" class = "blog-post-mywebsite"<?php post_class(); ?>>
        <header class="entry-header">
            <?php
            $my_date = the_date( '', '<h3>', '</h3>', false );
            echo $my_date;
            ?>
            <?php
            if ( is_single() ) :
                the_title( '<h1 class="entry-title">', '</h1>' );
            else :
                the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' );
            endif;
            ?>
        </header><!-- .entry-header -->


        <?php $images = get_field('slideshow'); ?>

        <?php if( $images ): ?>

            <div id="slider" class="flexslider">
            <ul class = "slides">
                <?php foreach( $images as $image ): ?>
                    <li>
                        <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
                    </li>
                <?php endforeach; ?>
            </ul>
            </div>

        <?php endif; ?>

            <?php if( get_field('video') ): ?>
                <div id="slider" class="flexslider">
                    <div class="video-fit">
                        <?php the_field(video); ?>
                    </div>
                </div>
            <?php endif; ?>

    <div class = "row" style = "padding: 32px 0;">
        <div class="col-md-4" style = "padding-left: 0px !important;">
            <?php if( get_field('address') ): ?>
                <h4>Address</h4>
                <?php the_field(address); ?>
            <?php endif; ?>

            <?php if( get_field('telephone') ): ?>
                <h4>Telephone</h4>
                <?php the_field(telephone); ?>
            <?php endif; ?>

                <?php if ( function_exists( 'ADDTOANY_SHARE_SAVE_KIT' ) ) {
                    ADDTOANY_SHARE_SAVE_KIT( array(
                        'buttons' => array( 'facebook', 'twitter', 'google_plus', 'pinterest', 'linkedin' ),
                    ) );
                } ?>
        </div>

        <div class = "col-md-8">
            <div>
                <?php if( get_field('blog_text') ): ?><?php the_field(blog_text); ?><?php endif; ?>
            </div>

        </div>
    </div>


    </article><!-- #post-## -->
</div>

THE JOURNAL TEMPLATE.php

<?php
/* Template Name: The Journal */
?>

<?php get_header(); ?>


<div class = “the journal">
  <?php get_template_part('template-parts/header/page-header-all'); ?>
  <div class = "row no-gutter the journal-blog">
    <div>
    <?php
      $args=array(
         'post_type' => 'post',
         'post_status' => 'publish',
         'orderby' => 'DESC'
      );

      $my_query = null;
      $my_query = new WP_Query($args);
    ?>

    <?php if (have_posts()) : ?>
      <?php while ($my_query->have_posts()) : $my_query->the_post();?>
        <?php if( $my_query->current_post == 0 && !is_paged() ) : ?>

          <div class = "row no-gutter" style = "padding-bottom: 32px;">
            <div class = "col-md-12" style="padding-left: 0px; padding-right: 0px;">
              <h2><?php echo the_title(); ?></h2>
              <a href="<?php echo esc_url( get_permalink() ); ?>"><?php the_post_thumbnail( 'full', array( 'class'  => 'img-fluid' ) ); ?></a>

              <div class = "row no-gutters" style = "padding: 32px 0;">
                    <div class = "col-md-4">
                        <h4><?php echo get_the_date(); ?></h4>
                    </div>
                    <div class="col-md-8"><?php $summary = get_field('blog_text');
                        echo substr($summary, 0, 300); ?>... <a href="<?php echo esc_url( get_permalink() ); ?>">Read More</a>
                    </div>
              </div>

            </div>
          </div>

        <?php endif; ?>

      <?php endwhile; ?>

      <?php
        $args=array(
           'post_type' => 'post',
           'post_status' => 'publish',
           'offset' => '1',
           'orderby' => 'DESC'
        );

        $my_query2 = null;
        $my_query2 = new WP_Query($args);
      ?>
        <?php $i = 0; ?>
      <?php while ($my_query2->have_posts()) : $my_query2->the_post();?>
        <?php if($i % 2 == 0) { ?>
            <div class="row">
                  <?php
                  }
                  ?>
              <div class="col-md-6 thumbnail">
                <a href="<?php echo esc_url( get_permalink() ); ?>"><?php the_post_thumbnail( 'full', array( 'class'  => 'img-fluid' ) ); ?></a>
                <h3><?php echo get_the_date(); ?></h3>
                <h2 class = "thumbnail-title"><?php echo the_title(); ?></h2>
                <h3 style = "padding-top: 0px; padding-bottom: 30px;"><a href = "<?php echo get_permalink(); ?>">Read More</a></h3>
              </div>
              <?php $i++; if($i % 2 == 0) { ?> </div><?php } ?>
     <?php endwhile; ?>
      <?php wp_reset_query(); ?>
    <?php endif; ?>
  </div>
  <? if ($i % 2 != 0) { ?></div><?php } ?>
  <div class = "col-md-3">
    <?php get_sidebar(); ?>
  </div>
  </div>
</div>
<?php get_footer(); ?>

content-tag.php

<?php
/**
 * Template part for displaying posts
 *
 * @link https://codex.wordpress/Template_Hierarchy
 *
 * @package mywebsite
 */

?>
<div class = "container blog-post-container-mywebsite">
  <h2><?php echo the_title(); ?></h2>
  <?php the_post_thumbnail( 'full', array( 'class'  => 'img-fluid' ) ); ?>
</div>

content-category.php

<?php
/**
 * Template part for displaying posts
 *
 * @link https://codex.wordpress/Template_Hierarchy
 *
 * @package mywebsite
 */

?>
<div class = "container blog-post-container-mywebsite">
  <h2><?php echo the_title(); ?></h2>
  <?php the_post_thumbnail( 'full', array( 'class'  => 'img-fluid' ) ); ?>
</div>

taxonomy-blog_category.php

<?php
/**
 * The template for displaying archive pages
 *
 * @link https://codex.wordpress/Template_Hierarchy
 *
 * @package mywebsite
 */

get_header(); ?>

  <style>
  .thumbnail img {
    max-height: 350px;
  }
  </style>
    <div id="primary" class="container content-area">
    <?php get_template_part('template-parts/header/page-header-all'); ?>

      <div class = "row journal-blog">
        <div style = "margin-top: 50px;">
          <?php
            if ( have_posts() ) : ?>

            <?php $i = 0; ?>

                <?php
                /* Start the Loop */
                while ( have_posts() ) : the_post(); ?>
               <?php if ( $i % 2 == 0 ) { ?><div class="row"><?php } ?>
                 <div class="col-md-6 thumbnail">
                   <?php the_post_thumbnail( 'full', array( 'class'  => 'img-fluid' ) ); ?>
                   <h3><?php echo get_the_date(); ?></h3>
                   <h2 class = "thumbnail-title"><?php echo the_title(); ?></h2>
                   <h3 style = "padding-top: 0px; padding-bottom: 30px;"><a href = "<?php echo get_permalink(); ?>">Read More</a></h3>
                 </div>
            <?php $i++; ?>
            <?php if ( $i % 2 == 0 ) { ?></div><?php } ?>
                <?php endwhile;
            endif; ?>
          <?php wp_reset_query(); ?>
        </div>
        <? if ($i % 2 != 0) { ?></div><?php } ?>
        <div class = "col-md-3">
          <?php get_sidebar(); ?>
        </div>
      </div>
    </div><!-- #primary -->

<?php
get_footer();
Share Improve this question edited Aug 22, 2019 at 14:44 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Aug 22, 2019 at 14:29 MIKE9004MIKE9004 11 bronze badge 1
  • Welcome to WordPress Stack Exchange! Please reduce your code to the absolute minimum. No one will read your entire theme code to help you. :) – fuxia Commented Aug 22, 2019 at 14:45
Add a comment  | 

1 Answer 1

Reset to default 0
function excerpt_readmore($more) {
    return '... <a href="'. get_permalink($post->ID) . '" class="readmore">' . 'Read More' . '</a>';
}
add_filter('excerpt_more', 'excerpt_readmore');

Please add above code into functions.php

发布评论

评论列表(0)

  1. 暂无评论