簡體   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