首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >构建一个Wordpress Permalink?

问构建一个Wordpress Permalink?
EN

Stack Overflow用户
提问于 2018-04-12 13:29:24
回答 1查看 39关注 0票数 0

替换昨天一个措辞不佳(删除)的问题。

我有一个预先建立的网站,需要Wordpress添加到它包含两个页面。

  1. 分页的博客文章列表,每页5篇(附有摘录)。使用帖子标题作为完整文章的链接。
  2. 完整的post permalink,(从第一页点击)。

我已经完成了第一部分,并使用以下循环进行工作。

代码语言:javascript
复制
<?php 
      $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

      $args = array(
        'posts_per_page' => 5,
        'paged' => $paged,
      );

      $loop = new WP_Query( $args );                    

      if ( $loop->have_posts() ) {
        while ( $loop->have_posts() ) : $loop->the_post();
 ?>

          <!-- Display the Title as a link to the Post's permalink. -->
          <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>

          <!-- Display the date and a link to other posts by this posts author.-->
          <small><?php the_time('F jS, Y'); ?> by <?php the_author(); ?></small>

          <!-- Display the Post as Excerpt. -->
          <div class="blogpost">
            <?php the_excerpt($more_link_text); ?>
          </div>

          <hr>

 <?php
       endwhile;

       $pagetotal = $loop->max_num_pages;

       if ($pagetotal > 1){

         $current_page = max(1, get_query_var('paged'));

         echo paginate_links(array(
          'base' => get_pagenum_link(1) . '%_%',
          'format' => 'page/%#%',
          'current' => $current_page,
          'total' => $pagetotal,
          'prev_text'    => __('« prev'),
          'next_text'    => __('next »'),
           ));
       }    
    }
    wp_reset_postdata(); ?>

上面的工作原理很好,包括分页方面,但是我现在被困在了我需要用这段代码做什么来使Permalinks显示为完整的post (目前它只是重新加载循环列表)。

我假设列表页和permalink页面都使用index.php?。

在Wordpress设置中,Permalinks设置为http://www.mywebsite.com/blog/this-is-a-post,相关的.htaccess已启动。

提前谢谢你的点灯或链接。

EN

回答 1

Stack Overflow用户

发布于 2018-04-12 15:09:19

当您说要显示"Permalink页面“时,您是指显示完整的博客文章,而不是列表吗?如果是这样的话,您将需要创建一个名为single.php的文件,并包含循环(最少)。

代码语言:javascript
复制
if (have_posts()) :
   while (have_posts()) :
      the_post();
         the_content();
   endwhile;
endif;

您可以在这里获得更多有关创建该文件以及它如何影响内容显示的信息:

Format

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49797872

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档