“阅读更多”会重定向到错误的页面

时间:2019-08-22 作者:MIKE9004

如果有人能帮我,我将不胜感激。我的博客帖子有问题。我让人按站点自定义,但他们在博客帖子上犯了一个错误。我不再和他们一起工作了。

发布

我有三个不同的页面以博客为特色(事件、新闻、杂志)。虽然这些帖子最初发布到正确的页面,但当您单击任何帖子的“阅读更多”时,它们都会在“日记”页面上打开。理想情况下,我希望每个博客都出现在各自的页面上并打开。下面您可以看到“single.php”、“tag.php”、“the Journal.php”、“content tag.php”、“taxononomy-blog\\u category.php”的相关php代码。如果有人能帮我,我将不胜感激。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.org/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.org/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(); ?>
内容标签。php

<?php
/**
 * Template part for displaying posts
 *
 * @link https://codex.wordpress.org/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.org/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.org/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();

1 个回复
SO网友:zain_ali

function excerpt_readmore($more) {
    return \'... <a href="\'. get_permalink($post->ID) . \'" class="readmore">\' . \'Read More\' . \'</a>\';
}
add_filter(\'excerpt_more\', \'excerpt_readmore\');
请将上述代码添加到函数中。php

相关推荐

WP ForLoop用于比较帖子的元数据信息以确定要显示的帖子

我在这里尝试的缺点是:我只想根据存储在自定义字段中的日期显示一篇文章。我只想显示符合两个条件的帖子1:日期必须尚未发生,即必须大于当前日期2:要显示的帖子日期必须是所有可能帖子中最接近当前日期的。这是下一个日期。我的问题是,当我要比较一篇文章和另一篇文章,然后使用WordPress循环只显示适当的文章时,我不知道从哪里开始。我想我需要使用for循环遍历每个帖子并进行比较,然后运行一个新的查询来显示我的一篇帖子。太长,读不下去了我可以使用forloop来检查WP\\u查询吗?如何访问其中的帖子信息?这是我的