繁体   English   中英

WordPress的主题

[英]wordpress theme

我正在创建wordpress主题并面临一个小问题。

在我的主题中,有一些页面,我想显示页面标题,例如“关于”,“博客”,我该怎么做。

第二,我想在博客页面下方显示所有帖子。 甚至我为博客创建了一个模板,但不幸的是,它没有发生。

感谢您的帮助。

您需要创建一个循环,以便WordPress可以查看并查看是否有任何内容,然后再显示它

因此,关于页面等的page.php将是:

<?php if (have_posts()) : while (have_posts()) : the_post();?>
<h1><?php the_title();?></h1><!--the title-->
<br />
<?php the_content();?><!--the content-->
<?php endwhile; endif;?>

第一个:使用<?php the_title(); ?> <?php the_title(); ?>以显示页面标题。

第二:要显示完整的帖子,请使用: <?php the_content(); ?> <?php the_content(); ?>

/*
* Template Name: Blog
*/

  //to show title

    the_title();


  //to show the post

  if (have_posts()) : while (have_posts()) : the_post();

  the_content();<!--the content-->

  endwhile; endif;

根据模板页面中的要求使用以上代码。

1.显示标题

只需添加<?php the_title(); ?> <?php the_title(); ?>

2.显示博客文章。 我编写了一些代码来显示页面中的所有博客文章,即时消息使用查询帖子,让它变得:

    if (is_page($your_page_id)) { ?>
    <div id="primary" class="content-area">
    <div id="content" class="site-content">
    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; // for paging
    $args = array('paged' => $paged);
    query_posts($args); // query posts
    if (have_posts()) :
        while (have_posts()) : the_post();
        get_template_part( 'content', get_post_format() ); // This code will display your posts
        endwhile;
        your_content_nav( 'nav-below' );
    endif;
    wp_reset_query(); // please, add this function to reset the query
    ?>         
    </div><!-- #content .site-content -->
    </div>
    } else {
 // normal page here
}

如果您要创建博客和关于页面。 您必须需要通过wordpress创建页面。 因此,单击您的wordpress页面button ,然后创建您的页面并根据您的想法设置sub-menus ...

对于第二个问题,答案是转到最新页面选择选项,然后为主页/索引/第一个屏幕选择静态页面,然后在页面选项下方选择要移动最新帖子内容的菜单。

如果要在页面中显示帖子,则需要首先为帖子创建类别,然后对每个帖子进行分类。 之后,您可以根据帖子类别创建页面。 现在,要在这些页面上发布帖子,您可以使用我在答案HERE中发布的get_posts()方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM