亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Home CMS Tutorial WordPress The whole process of WordPress theme creation (8): making index.php

The whole process of WordPress theme creation (8): making index.php

Feb 21, 2023 am 10:00 AM
wordpress

I introduced you to "The whole process of WordPress theme production (7): Making sidebar.php". This article continues to introduce to you how to make index.php. Let's take a look. ~

The whole process of WordPress theme creation (8): making index.php

We have already created sidebar.php, footer.php and header.php for all public pages of the blog. Starting today, we will create separate pages. Now what we want to create is the index page index.php. Here we can temporarily understand it as the home page, but in fact it is not as simple as the home page.

The main page is the article list, which lists the articles on your blog one by one. You may have noticed that the style of each article on the homepage is the same, but the text content such as title, time, author, and abstract are different, huh! We only need the HTML code of one article to make index.php. We don't need to manually write the HTML of so many articles. Moreover, this is not dynamic content. We only need one loop to display all articles on the home page. A loop is to do something repeatedly. The loop here is to repeatedly output articles. If you have learned any computer programming language before, it is not difficult to understand what a loop is, and the functions of a loop can be easily understood, such as while, for, foreach...

在Insert a sentence here, if you really want to know how to make a theme, please open the text editor, follow me step by step, modify step by step, refresh your blog every time you make a modification to see what changes, so Only then can you deepen your understanding. If you're too lazy to do it, I suggest you don't read the following content, as it won't be of much help to you.

Now start making index.php. Initially, there are three articles in index.php. When you open index.php, you can see the three tags of the article . Now we will delete the codes of the two articles, leaving one article and remove the article abstract. The modified code is like this:

<?php get_header(); ?>
	<!-- Column 1 /Content -->
	<div class="grid_8">
		<!-- Blog Post -->
		<div class="post">
			<!-- Post Title -->
			<h3 class="title"><a href="single.html">Loreum?ipsium?massa?cras?phasellus</a></h3>
			<!-- Post Data -->
			<p class="sub"><a href="#">News</a>,?<a href="#">Products</a>???31st?Sep,?09???<a href="#">1?Comment</a></p>
			<div class="hr dotted clearfix">?</div>
			<!-- Post Image -->
			<img class="thumb" alt="" src="<?php bloginfo(&#39;template_url&#39;); ?>/images/610x150.gif"?/>
			<!-- Post Content -->
			
			<!-- Read More Button -->
			<p class="clearfix"><a href="single.html" class="button right">?Read?More...</a></p>
		</div>
		<div class="hr clearfix">?</div>
		
		<!-- Blog Navigation -->
		<p class="clearfix">?<a href="#" class="button float"><<?Previous?Posts</a>?<a href="#" class="button float right">Newer?Posts?>></a>?</p>
	</div>
	<?php get_sidebar(); ?><?php get_footer(); ?>
As you can see from the above code, the html skeleton of an article is:
<div class="post">
	<!-- Post Title -->
	<h3 class="title"><a href="single.html">文章標(biāo)題</a></h3>
	<!-- Post Data -->
	<p class="sub"><a href="#">標(biāo)簽1</a>, <a href="#">標(biāo)簽12</a> ? 發(fā)布時(shí)間 ? <a href="#">評(píng)論數(shù)</a></p>
	<div class="hr dotted clearfix"> </div>
	<!-- Post Image 文章的縮略圖 -->
	<img class="thumb" alt="" src="<?php bloginfo(&#39;template_url&#39;); ?>/images/610x150.gif" />
	<!-- Post Content -->
	文章內(nèi)容
	<!-- Read More Button -->
	<p class="clearfix"><a href="single.html" class="button right"> 閱讀全文按鈕</a></p>
</div>
<div class="hr clearfix"> </div>

The html skeleton of articles with different themes is different. If you are familiar with html, You can quickly identify the skeleton of the article. The above is the skeleton of our theme. Based on this, we will add dynamic content to index.php:

1. Add article title

Found:

<h3 class="title"><a href="single.html">Loreum ipsium massa cras phasellus</a></h3>

Changed to:

<h3 class="title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h3>

Here are the explanations of these php functions:

  • Output the URL link of the article
  • Output the title of the article

2. Add article tags

Many of us like to add some tags when writing articles, and we have also added a "tag cloud" to the sidebar, our theme Tags should be supported. Found:

<a href="#">News</a>, <a href="#">Products</a>

Changed to:

<?php the_tags(&#39;標(biāo)簽:&#39;, &#39;, &#39;, &#39;&#39;); ?>

Function reference: the_tags

3. Add date

Found: 31st Sep, 09

Changed to:

<?php the_time(&#39;Y年n月j日&#39;) ?>

Function reference: the_time

About Y in this function For the date format obtained by n j, you can refer to the document (Chinese) and choose the time format you like: zh-cn: Custom time and date

Maybe you have read the time and date documents provided above, or If you are confused, here are a few examples. You can almost follow the example and specify the time and date format you like:

##99-05-01 02:09:08

4、顯示評(píng)論數(shù)

現(xiàn)在我們來添加評(píng)論數(shù)代碼,查找代碼:

<a href="#">1 Comment</a>

改成:

<?php comments_popup_link(&#39;0 條評(píng)論&#39;, &#39;1 條評(píng)論&#39;, &#39;% 條評(píng)論&#39;, &#39;&#39;, &#39;評(píng)論已關(guān)閉&#39;); ?>

該函數(shù)會(huì)根據(jù)文章的評(píng)論數(shù)量顯示不同的文字鏈接,0 條評(píng)論、1 條評(píng)論等等,當(dāng)然能你可以根據(jù)自己的愛好定制文字內(nèi)容。該鏈接會(huì)直接打開對(duì)應(yīng)的文章,并移動(dòng)到文章的評(píng)論區(qū).

函數(shù)參考:comments_popup_link

5、添加編輯按鈕

如果文章作者已登錄,我們將允許他在首頁(yè)點(diǎn)擊對(duì)應(yīng)文章的編輯按鈕,就可以直接修改文章,這個(gè)功能是可選的,你可以不添加。接上面的評(píng)論按鈕,我們?cè)谄浜竺嫣砑酉鄳?yīng)代碼:

<?php comments_popup_link(&#39;0 條評(píng)論&#39;, &#39;1 條評(píng)論&#39;, &#39;% 條評(píng)論&#39;, &#39;&#39;, &#39;評(píng)論已關(guān)閉&#39;); ?>

函數(shù)參考:edit_post_link

6、添加文章內(nèi)容

可能有些人喜歡在首頁(yè)輸出全文,而有些人喜歡在首頁(yè)輸出文章摘要,這里提供兩種方案,任君選擇。查找:

將其改成:

<!-- Post Content -->
<?php the_excerpt(); ?>

只要在寫文章的時(shí)候在"摘要"框內(nèi)填寫摘要,在首頁(yè)顯示的就是摘要,如果不填就輸出全文!以下是方案二,用于輸出全文,除非你在文章中使用了,代碼修改:

<!-- Post Content -->
<?php the_content(&#39;閱讀全文...&#39;); ?>

函數(shù)參考:

  • the_excerpt
  • the_content

7、閱讀全文

這里給添加閱讀全文鏈接,如果在6、添加文章內(nèi)容中你選擇了輸出全文,本步驟可以忽略,查找代碼:

<a href="single.html" class="button right"> Read More...</a>

改成:

<a href="<?php the_permalink(); ?>" class="button right">閱讀全文</a>

8、添加文章循環(huán)

到目前為止,你的首頁(yè)還只能顯示一篇文章,要想輸出所有文章,需要我們之前提到的循環(huán)。查找代碼:

改成:

<!-- Blog Post --><?php if (have_posts()) : while (have_posts()) : the_post(); ?>

再查找:

<div class="hr clearfix"> </div>

改成:

<div class="hr clearfix"> </div>

再次查找:

</div><?php get_sidebar(); ?>

改成:

<?php else : ?>
<h3 class="title"><a href="#" rel="bookmark">未找到</a></h3>
<p>沒有找到任何文章!</p>
<?php endif; ?>
</div>
<?php get_sidebar(); ?>

好了,現(xiàn)在查看你的主頁(yè),是不是可以顯示多篇文章了呢?文章數(shù)量取決于你在后臺(tái)設(shè)置每頁(yè)可顯示的文章數(shù)量。以上的循環(huán)可以簡(jiǎn)化為以下內(nèi)容,這樣看起來應(yīng)該比較容易理解了,在endwhile之前不斷地輸出每篇文章,直至文章數(shù)量達(dá)到每頁(yè)顯示的最大文章數(shù)量;如果你的博客上一篇文章都沒有,就會(huì)輸入無文章提示。

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
文章html骨架
<?php endwhile; ?>
<?php else : ?>
輸出找不到文章提示
<?php endif; ?>

9、添加文章分頁(yè)

上面你已經(jīng)看到,每頁(yè)只能顯示部分文章,要想看下一頁(yè),就得添加分頁(yè)?,F(xiàn)在查找代碼:

<p class="clearfix"> <a href="#" class="button float"><< Previous Posts</a> <a href="#" class="button float right">Newer Posts >></a> </p>

改成:

<p class="clearfix"><?php previous_posts_link(&#39;<< 查看新文章&#39;, 0); ?> <span class="float right"><?php next_posts_link(&#39;查看舊文章 >>&#39;, 0); ?></span></p>

參考函數(shù):

  • previous_posts_link
  • next_posts_link

10、文章縮略圖

對(duì)于大部分人來說,不太需要文章縮略圖的功能,而且有很多插件可以實(shí)現(xiàn)這個(gè)功能。這里我們將首頁(yè)的文章縮略圖代碼刪除:

<!-- Post Image --><img class="thumb" alt="" src="<?php bloginfo(&#39;template_url&#39;); ?>/images/610x150.gif" />

另外,還有個(gè)存檔頁(yè)面的模板archive.php,跟index.php的制作過程完全一樣,只不過需要在functions.php里添加一個(gè)函數(shù),這里就不再羅嗦,下載自己看吧,注意:functions.php中的代碼已經(jīng)修改,要想讓你的分類、標(biāo)簽等存檔頁(yè)能夠正常顯示,請(qǐng)下載最新的functions.php覆蓋原來的。另外,標(biāo)簽頁(yè)和分類頁(yè)支持在該頁(yè)面頂部顯示介紹,前提是你在后臺(tái)文章標(biāo)簽和分類處要填上了描述。

好了,到目前這個(gè)主題也像個(gè)樣子了,不過還有很多要完善,后面我們將繼續(xù)完善!

推薦學(xué)習(xí):《WordPress教程

The above is the detailed content of The whole process of WordPress theme creation (8): making index.php. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1488
72
How to adjust the wordpress article list How to adjust the wordpress article list Apr 20, 2025 am 10:48 AM

There are four ways to adjust the WordPress article list: use theme options, use plugins (such as Post Types Order, WP Post List, Boxy Stuff), use code (add settings in the functions.php file), or modify the WordPress database directly.

10 latest tools for web developers 10 latest tools for web developers May 07, 2025 pm 04:48 PM

Web development design is a promising career field. However, this industry also faces many challenges. As more businesses and brands turn to the online marketplace, web developers have the opportunity to demonstrate their skills and succeed in their careers. However, as demand for web development continues to grow, the number of developers is also increasing, resulting in increasingly fierce competition. But it’s exciting that if you have the talent and will, you can always find new ways to create unique designs and ideas. As a web developer, you may need to keep looking for new tools and resources. These new tools and resources not only make your job more convenient, but also improve the quality of your work, thus helping you win more business and customers. The trends of web development are constantly changing.

How to import the source code of wordpress How to import the source code of wordpress Apr 20, 2025 am 11:24 AM

Importing WordPress source code requires the following steps: Create a sub-theme for theme modification. Import the source code and overwrite the files in the sub-topic. Activate the sub-theme to make it effective. Test the changes to make sure everything works.

How to build a website for wordpress host How to build a website for wordpress host Apr 20, 2025 am 11:12 AM

To build a website using WordPress hosting, you need to: select a reliable hosting provider. Buy a domain name. Set up a WordPress hosting account. Select a topic. Add pages and articles. Install the plug-in. Customize your website. Publish your website.

How to add your WordPress site in Yandex Webmaster Tools How to add your WordPress site in Yandex Webmaster Tools May 12, 2025 pm 09:06 PM

Do you want to connect your website to Yandex Webmaster Tools? Webmaster tools such as Google Search Console, Bing and Yandex can help you optimize your website, monitor traffic, manage robots.txt, check for website errors, and more. In this article, we will share how to add your WordPress website to the Yandex Webmaster Tool to monitor your search engine traffic. What is Yandex? Yandex is a popular search engine based in Russia, similar to Google and Bing. You can excel in Yandex

How to set, get and delete WordPress cookies (like a professional) How to set, get and delete WordPress cookies (like a professional) May 12, 2025 pm 08:57 PM

Do you want to know how to use cookies on your WordPress website? Cookies are useful tools for storing temporary information in users’ browsers. You can use this information to enhance the user experience through personalization and behavioral targeting. In this ultimate guide, we will show you how to set, get, and delete WordPresscookies like a professional. Note: This is an advanced tutorial. It requires you to be proficient in HTML, CSS, WordPress websites and PHP. What are cookies? Cookies are created and stored when users visit websites.

How to register a wordpress account How to register a wordpress account Apr 20, 2025 am 11:45 AM

To create an account on WordPress, simply visit its website, select the registration option, fill in the registration form, and verify your email address. Other ways to register include using a Google account or Apple ID. The benefits of signing up include creating a website, gaining features, joining the community, and gaining support.

How to fix HTTP image upload errors in WordPress (simple) How to fix HTTP image upload errors in WordPress (simple) May 12, 2025 pm 09:03 PM

Do you need to fix HTTP image upload errors in WordPress? This error can be particularly frustrating when you create content in WordPress. This usually happens when you upload images or other files to your CMS using the built-in WordPress media library. In this article, we will show you how to easily fix HTTP image upload errors in WordPress. What is the reason for HTTP errors during WordPress media uploading? When you try to upload files to Wo using WordPress media uploader

See all articles
PHP code Output content
May 1, 1999
May 01, 1999
< ?php the_time('Y-m-d') ?>1999-05-01
      <code id="xulls"></code>

          <blockquote id="xulls"></blockquote>