Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537
文鏈接:How to Hide Title for Selective WordPress Posts and Pages
原文標題:How to Hide the Title for Selective WordPress Posts and Pages
由遼觀進行翻譯整理。
Do you want to hide the title for selective WordPress posts and pages?
您想要隱藏特定的WordPress文章和頁面的標題嗎?
Titles can be helpful for both search engines and visitors, but not every page needs to display a title depending on its design.
標題對于搜索引擎和訪問者都很有幫助,但并非每個頁面都需要根據其設計顯示標題。
In this article, we will show you how to hide the title for specific WordPress posts and pages.
在這篇文章中,我們將向您展示如何隱藏特定的WordPress文章和頁面的標題。
When you create a WordPress page or post the first thing you’ll see is an ‘Add title’ field where you will type your title.
當您創建WordPress頁面或文章時,您首先會看到一個“添加標題”的字段,您可以在其中鍵入標題。
Most WordPress themes show this title at the top of the page or post. A descriptive, relevant title can let visitors know they’re in the right place and what to expect from this page.
大多數WordPress主題會在頁面或文章的頂部顯示這個標題。一個描述性的、相關的標題可以讓訪問者知道他們來到了正確的地方,并且可以對這個頁面有所期待。
Titles may be helpful, but not every page or post needs a title. Your website’s homepage is one common example.
標題可能是有幫助的,但并不是每個頁面或文章都需要標題。您網站的首頁就是一個常見的例子。
At other times you may want to show the page’s title in a different area. For example you might start your landing page with an eye-catching banner, and then show the title further down the page.
在其他情況下,您可能希望在不同的區顯示頁面的標題。例如,您可能會在引人注目的橫幅上開始您的登陸頁面,然后在頁面下方顯示標題。
In this guide, we’ll be covering three different methods to hide the post or page title in WordPress. Simply click the links below to jump to the method you prefer.
在本指南中,我們將介紹三種在WordPress中隱藏帖子或頁面標題的不同方法。只需點擊面的鏈接,跳轉到您喜歡的方法。
If you’re using WordPress 5.9 or later, and have aWordPress themethat supports full site editing, then you can use this method to remove the title from all posts or all pages.
如果您使用的是WordPress 5.9或更高版本,并且擁有一個支持全站編輯的WordPress主題,那么您可以使用這種方法來刪除所有帖子或頁面的標題。
Not sure if your theme support full site editing?
不確定您的主題是否支持全站編輯?
If it does, then you’ll see the menu optionAppearance ? Editoravailable in your WordPress dashboard.
如果支持全站編輯,您將在WordPress儀表板中看到菜單選項“外觀 ? 編輯器”。
After clicking on ‘Editor’, the full site editor will launch.
點擊“編輯器”后,將啟動全站編輯器。
From here, you’ll need to select thetemplateyou want to edit by clicking on the dropdown at the top of the page, and then clicking on ‘Browse all templates’.
在這里,您需要通過點擊頁面頂部的下拉菜單,并點擊“瀏覽所有模板”,來選擇您想要編輯的模板。
In this example, we’ll edit the Single Post template so that we can hide all our blog post titles.
在這個例子中,我們將編輯單篇文章模板,以便隱藏所有博客文章的標題。
To hide the title, first you’ll need to click on the blog post title. Then, simply click on the three dots options menu and select the ‘Remove Post Title’ option at the bottom.
要隱藏標題,首先需要點擊博客文章的標題。然后,只需點擊三個點的選項菜單,并在底部選擇“刪除文章標題”選項。
Don’t forget to click the Save button at the top of the screen after you’re done customizing the template.
在您完成對模板進行自定義后,不要忘記點擊屏幕頂部的保存按鈕。
That’s it, you’ve hidden the title on all your blog posts.
完成了!您已經在所有博客文章中隱藏了標題。
If you’d like a way to hide the title only on specific posts or pages, the next method should work for you.
如果您想要僅在特定的文章或頁面上隱藏標題,下一種方法可能適合您。
You can hide a page or post’s title by adding custom CSS code to theWordPress Customizer. This method simply hides the title from your visitors, but it still loads in the page’s HTML code.
您可以通過向WordPress自定義器添加自定義CSS代碼來隱藏頁面或文章的標題。這種方法只是從訪客的視野中隱藏標題,但它仍然會在頁面的HTML代碼中加載。
This means that search engines can still use the title to help them understand your page’s contents, which is good for yourWordPress website’s SEOand can help you get more traffic.
這意味著搜索引擎仍然可以使用標題來幫助它們理解您頁面的內容,這對于您的WordPress網站的SEO非常有益,可以幫助您獲得更多的流量。
We’ll show you how to hide the title on specific posts or pages, or on all your posts and pages.
我們將向您展示如何在特定的文章或頁面上隱藏標題,或者在所有文章和頁面上都隱藏標題。
To hide a page or post’s title using CSS, you just need to know its ID.
要使用CSS隱藏頁面或文章的標題,您只需要知道它的ID。
In your WordPress dashboard, either go toPosts ? All Posts, orPages ? All Pages. Then find the page or post where you want to hide the title.
在WordPress儀表板中,要么轉到“文章” ? “所有文章”,要么轉到“頁面” ? “所有頁面”。然后找到您想要隱藏標題的頁面或文章。
You can now open this post or page for editing.
您現在可以打開此文章或頁面進行編輯。
Now simply take a look at the URL in your browser’s address bar.
現在只需查看瀏覽器地址欄中的URL。
You should see a ‘post=’ section followed by a number. For example ‘post=100.’
您應該看到一個由數字跟隨的“post=”部分。例如,“post=100”。
This is your post’s ID. Make a note of this number, as you’ll be using it in your CSS code.
這是您的文章的ID。請記下這個數字,因為您將在CSS代碼中使用它。
You can now go to Appearance ? Customize.
現在您可以轉到“外觀” ? “自定義”。
This launches the WordPress Customizer.
這將啟動WordPress自定義器。
In the sidebar, simply click on Additional CSS.
在側邊欄中,只需單擊“附加CSS”。
Now scroll to the bottom of the sidebar.
現在滾動到側邊欄底部。
You should now see a small text editor. This is where you’ll type your CSS code.
您現在應該看到一個小型文本編輯器。這是您輸入CSS代碼的地方。
If you want to hide the title for a post, you’ll need to use the following code.
如果您想隱藏文章的標題,您需要使用以下代碼。
Just make sure you replace the ‘100’ with the post ID you got in the previous step.
只需確保將“100”替換為您在前一步驟中獲得的文章ID。
.postid-100 .entry-title {
display: none;
}
If you want to hide a page’s title, you’ll need to use some slightly different code.
如果您想隱藏頁面的標題,您需要使用略有不同的代碼。
Once again make sure you replace the ‘100’ with your real page ID.
如果您想隱藏頁面的標題,您需要使用略有不同的代碼。
.page-id-100 .entry-title {
display: none;
}
Next, just scroll to the top of the page.
接下來,將頁面滾動到頂部。
You can then click on the blue Publish button.
然后,您可以點擊藍色的“發布”按鈕。
Now if you check this page or post, the title should have disappeared.
現在,如果您檢查此頁面或文章,標題應該已經消失了。
Is the title still there?
標題還在嗎?
If this method hasn’t worked for you, your WordPress theme may be using a different CSS class. This means your page or post ID will be different from the number shown in its URL.
如果這種方法對您不起作用,那么您的WordPress主題可能正在使用不同的CSS類。這意味著您的頁面或文章ID將與其URL中顯示的數字不同。
To get the correct ID, you’ll need to use your browser’s developer console.
要獲取正確的ID,您需要使用瀏覽器的開發者控制臺。
To start, head over to the page or post on your WordPress website. You can then open your browser’s developer console.
首先,轉到WordPress網站上的頁面或文章。然后,您可以打開瀏覽器的開發者控制臺。
This step will vary depending on which web browser you’re using. For example, if you have Chrome then you can use the Control+Shift+J keyboard shortcut on Windows, or the Command+Option+J shortcut on Mac.
這一步驟會根據您使用的Web瀏覽器而有所不同。例如,如果您使用的是Chrome瀏覽器,您可以在Windows上使用Control+Shift+J鍵盤快捷鍵,或者在Mac上使用Command+Option+J快捷鍵。
Chrome users can also Control+click anywhere on the page or post, and then select Inspect.
Chrome用戶還可以在頁面或文章的任何位置Control+點擊,然后選擇”Inspect“。
If you’re unsure how to open the developer console, you can always check your browser’s website or official documentation for more information.
如果您不知道如何打開開發者控制臺,您可以隨時查看瀏覽器的網站或官方文檔以獲取更多信息。
In the developer console, click on the three dotted icon. You can then select ‘Search.’
在開發者控制臺中,點擊三個點的圖標。然后,您可以選擇“搜索”。
You should now see a search bar towards the bottom of the developer console.
現在,您應該會在開發者控制臺的底部看到一個搜索欄。
In this bar, type <body class, then simply press the Enter key on your keyboard.
在此欄中,鍵入<body class,然后只需按下鍵盤上的Enter鍵。
If you’re looking at a WordPress page, you should see something similar to the following.
如果您正在查看一個WordPress頁面,您應該會看到類似以下的內容。
<body class="page-template-default page page-id-78 logged-in admin-bar
no-customize-support wp-embed-responsive is-light-theme no-js singular">
In the sample code above, you can see that the ‘page-id’ value is 78.
在上面的示例代碼中,可以看到"page-id"的值為78。
If you’re inspecting a WordPress post, the console should show something like:
如果您在檢查WordPress文章,控制臺應該顯示類似以下內容:
<body class="post-template-default single single-post postid-100 single-format-standard logged-in admin-bar no-customize-support wp-embed-responsive is-light-theme no-js singular">
In that example, the ‘postid’ value is 100. You can now use this value with the CSS code we provided in the previous step.
在這個示例中,"postid"的值為100。您現在可以將這個值與我們在上一步中提供的CSS代碼一起使用。
Simply add this code to your website using the WordPress Customizer, following the process described above.
只需按照上述描述的過程,使用WordPress自定義器將此代碼添加到您的網站上即可。
You can now take a look at the page or post. The title should have vanished.
您現在可以查看頁面或文章。標題應該已經消失了。
To hide the titles for all your pages and posts, copy/paste the following into the text editor.
要隱藏所有頁面和帖子的標題,請將以下內容復制/粘貼到文本編輯器中。
.entry-title {
display: none;
}
Do you want to hide the titles for all your pages, but not your posts? To hide all the page titles, copy/paste the following into the small text editor.
您想要隱藏所有頁面的標題,但不隱藏帖子的標題嗎?為了隱藏所有頁面的標題,請將以下內容復制/粘貼到小文本編輯器中。
.page .entry-title {
display: none;
}
Another option is hiding the title for all of your posts. You can do this using the following CSS.
另一個選擇是隱藏所有帖子的標題。您可以使用以下CSS代碼來實現。
.post .entry-title {
display: none;
}
Sometimes you may want to hide the titles for all your posts and pages.
有時候您可能希望隱藏所有頁面和帖子的標題。
To do that, add the following.
要做到這一點,請添加以下代碼。
.entry-title {
display: none;
}
You can easily hide the title for selective posts and posts using Hide Page And Post Title. This free plugin lets you hide the title of any page, post, or even custom posts types.
您可以使用Hide Page And Post Title輕松地隱藏選擇性的頁面和帖子的標題。這個免費插件允許您隱藏任何頁面、帖子,甚至自定義帖子類型的標題。
譯者注:請注意,隱藏標題后,頁面或帖子的標題將不再顯示在前臺,但標題仍然存在于后臺編輯界面,您可以隨時修改和恢復標題的顯示。
First you’ll need to install and activate the Hide Page And Post Title plugin. If you need help, you can follow our tutorial on how to install a WordPress plugin.
首先,您需要安裝并激活Hide Page And Post Title插件。如果需要幫助,您可以按照我們的WordPress插件安裝教程進行操作。
Upon activation, open the page, post or custom post you want to edit.
在激活插件后,打開您想要編輯的頁面、帖子或自定義帖子。
Now simply scroll to the bottom of the right sidebar.
現在只需要向右邊欄的底部滾動。
Here you’ll find a new ‘Hide Page and Post Title’ box.
在這里,您會找到一個名為“隱藏頁面和帖子標題”的新框。
譯者注:請注意,這個框可能在編輯頁面或帖子的不同位置,具體取決于您的主題或其他插件的設置。通常,您可以在編輯頁面或帖子的右側邊欄或編輯器中找到該框。
To hide the title, just click to select the ‘Hide the title’ checkbox. You can then update or publish this post as normal.
要隱藏標題,只需點擊選擇“隱藏標題”復選框。然后,您可以像正常編輯頁面或發布帖子一樣更新或發布。
That’s it! If you visit the page you’ll notice that the title has disappeared.
就是這樣!如果您訪問該頁面,您會注意到標題已經消失了。
At some point you may need to restore this page or post’s title.
在某些時候,您可能需要恢復該頁面或帖子的標題。
This is easy. Just open the page or post for editing. Then click to deselect the same ‘Hide the title’ checkbox.
這很簡單。只需打開要編輯的頁面或帖子。然后點擊取消選擇相同的“隱藏標題”復選框。
Don’t forget to click on the Update button at the top of the screen. Now if you visit this page, the title should have reappeared.
不要忘記點擊屏幕頂部的“更新”按鈕。現在,如果您訪問此頁面,標題應該已經重新出現。
Another option is to hide the title using a page builder plugin.
另一個選項是使用頁面構建器插件隱藏標題。
SeedProd is the best WordPress page builder plugin in the market. You can use this plugin to easily creating custom pages or even create your own WordPress theme.
SeedProd是市場上最好的WordPress頁面構建器插件。您可以使用這個插件輕松創建自定義頁面,甚至創建自己的WordPress主題。
This means you can easily hide the title on a custom page design or your theme.
這意味著您可以輕松地在自定義頁面設計或您的主題中隱藏標題。
SeedProd comes with a template library with over 150+ templates you can use as a starting point for your page designs. Let’s see how easy it is to remove the title from one of these theme templates.
SeedProd附帶了一個模板庫,其中包含150多個模板,您可以用作頁面設計的起點。讓我們看看如何從其中一個主題模板中刪除標題。
In your WordPress dashboard go to SeedProd ? Template Builder. You can then click on the Themes button.
在WordPress儀表板中,轉到SeedProd ? 模板構建器。然后,您可以點擊主題按鈕。
This launches the SeedProd template library. You can now browse through all of the different designs.
這將啟動SeedProd模板庫。您現在可以瀏覽所有不同的設計。
To take a closer look at a template simply hover your mouse over it. Then click on the magnifying glass icon.
要仔細查看模板,只需將鼠標懸停在其上,然后點擊放大鏡圖標。
This will open the template in a new tab.
這將在一個新標簽中打開模板。
When you find a template that you want to use, hover your mouse over that template. Then simply click on the checkmark icon.
當您找到一個要使用的模板時,將鼠標懸停在該模板上。然后只需點擊復選標記圖標即可。
This adds all of this template’s designs to your WordPress dashboard.
這將把這個模板的所有設計添加到您的WordPress儀表板中。
There are usually different designs for different types of content.
通常針對不同類型的內容有不同的設計。
You can use these templates to hide the title for the different content types. For example, many SeedProd templates have a separate design for the homepage.
您可以使用這些模板來隱藏不同內容類型的標題。例如,許多SeedProd模板都有一個專門的設計用于首頁。
To hide the title for your homepage, you would simply need to edit the Homepage template.
要隱藏首頁的標題,您只需要編輯首頁模板即可。
To hide the title for all your posts, you’ll typically need to edit the Single Post template.
要隱藏所有文章的標題,通常需要編輯Single Post模板。
Meanwhile if you want to hide the title from your pages you’ll usually edit SeedProd’s Single Page template.
而如果您想隱藏頁面的標題,則通常需要編輯SeedProd的Single Page模板。
To edit a template hover your mouse over it.
要編輯模板,請將鼠標懸停在模板上。
You can then go ahead and click on the Edit Design link.
然后,您可以點擊“編輯設計”鏈接進行編輯。
This opens this design in the SeedProd drag and drop editor. To hide the title, find either the Post or Page Title.
這將在SeedProd的拖放編輯器中打開此設計。要隱藏標題,請找到“文章標題”或“頁面標題”。
Once you spot this title, give it a click. SeedProd’s sidebar will now show all of the settings for the selected area.
一旦找到標題,請點擊它。SeedProd的側邊欄將顯示所選區域的所有設置。
At the top of this panel you should see either Post Title or Page Title.
在這個面板的頂部,您應該看到“文章標題”或“頁面標題”。
After confirming that you’ve selected the right area, hover over the Post Title or Page Title in the main SeedProd editor.
確認選擇了正確的區域后,在主SeedProd編輯器中將鼠標懸停在“文章標題”或“頁面標題”上。
You should now see a row of controls.
現在您應該看到一行控件。
To remove the title from this design just click on the Trash icon.
要從此設計中刪除標題,只需點擊垃圾桶圖標。
SeedProd will ask whether you really want to delete the title. To go ahead and remove it, simply click on ‘Yes, delete it!’
SeedProd將詢問您是否真的要刪除標題。要繼續刪除,請點擊“是,刪除它!”
The title will now disappear from your design.
標題現在將從您的設計中消失。
To see how this will look on your website click on the Preview button.
要查看它在您的網站上的效果,請點擊“預覽”按鈕。
When you’re happy with your design click on the Publish button.
當您對設計滿意時,請點擊“發布”按鈕。
Depending on how your site is set up, you may need to remove the title from some additional templates. For example you might want to hide the title for all your posts and pages. In this case, you would typically need to edit both the Single Post and Single Page templates.
根據您的網站設置,您可能需要從一些額外的模板中刪除標題。例如,您可能希望隱藏所有文章和頁面的標題。在這種情況下,您通常需要編輯單篇文章和單頁模板。
If you’re unsure then it may help to review all the designs that make up your theme. To do this simply go to SeedProd ? Theme Builder.
如果您不確定,可以檢查一下組成您主題的所有設計。只需轉到SeedProd ? 主題構建器。
You should now see a list of all your different designs. You can now edit any of these templates following the same process described above.
您現在應該可以看到所有不同設計的列表。您現在可以按照上面描述的相同步驟編輯任何這些模板。
Before hiding your page or post titles, there are some effects you should think about, such as the impact this action will have on your website’s SEO.
在隱藏頁面或文章標題之前,您應該考慮一些影響,比如此操作對您的網站SEO的影響。
That being said, here are some of the most frequently asked questions about hiding the page and post title.
話雖如此,以下是關于隱藏頁面和文章標題的一些常見問題:
When it comes to hiding the title there seems like an easy fix. As you’re creating your page, just leave the title field blank.
在隱藏標題方面,似乎有一個簡單的解決方法。在創建頁面時,只需將標題字段留空即可。
At first this does seem to fix the problem. WordPress will display this post to visitors without a title. However, there are a few problems.
起初,這似乎解決了問題。WordPress將在沒有標題的情況下向訪問者顯示此頁面或文章。然而,確實存在一些問題。
Firstly, this page or post will appear as ‘(no title)’ in your WordPress dashboard. This makes it more difficult to keep track of your pages.
首先,在WordPress儀表板中,該頁面或文章將顯示為“(no title)”(無標題)。這使得跟蹤頁面變得更加困難。
If you create lots of different ‘(no title)’ posts, then how do you know which is your contact us page? And which page is your homepage?
如果您創建了許多不同的“(no title)”文章,那么您如何知道哪個是您的聯系我們頁面?哪個是您的首頁?
WordPress also uses the title to create the page’s URL.
WordPress還使用標題來創建頁面的URL。
If you don’t provide a title, then by default WordPress uses a number instead, such as ‘www.mywebsite/8.’
如果您不提供,WordPress默認使用一個數字,“wwwwebsite/8”。
Visitors often use the URL to help them understand where they are on your WordPress website, so ‘www.mywebsite/8’ isn’t particularly helpful.
訪問者通常使用URL來幫助他們理解自己在WordPress網站上的位置,“www.mywebsite/8”并不特別有幫助。
This vague URL is not an SEO-friendly permalink, so search engines may have a harder time understanding what your content is about and including it in the relevant search results.
這種模糊的URL不是一個友好的SEO永久鏈接,所以搜索引擎可能很難理解您的內容是關于什么,并將其包含在相關的搜索結果中。
If you prefer to hide a page or post’s title, you’ll want to spend some extra time fine-tuning the rest of your WordPress SEO, including setting an SEO title. This will help ensure that the search engines understand your page’s content, even without the title.
如果您希望隱藏頁面或文章的標題,您需要額外花費一些時間來優化您的WordPress SEO,包括設置SEO標題。這樣可以確保搜索引擎即使沒有標題也能理解頁面的內容。
Here you’ll need a good SEO plugin, since WordPress doesn’t let you do this by default.
在這里,您將需要一個好的SEO插件,因為WordPress默認情況下不允許您這樣做。
We recommend using AIOSEO, the best SEO plugin for WordPress in the market. This beginner friendly SEO toolkit is used by over 3 million websites.
我們推薦使用AIOSEO,這是市場上最好的WordPress SEO插件。這個適合初學者的SEO工具包被超過300萬個網站使用。
If you need help getting started, then please refer to our guide on how to properly set up All in One SEO in WordPress.
如果您需要幫助入門,請參考我們的指南,了解如何正確設置WordPress中的All in One SEO。
To make sure your titles are optimized, you can see our guide on how to use the headline analyzer in AIOSEO.
為了確保您的標題被優化,您可以參考我們的指南,了解如何使用AIOSEO中的標題分析器。
We hope this article helped you learn how to hide the title for selective WordPress posts and pages. You can also go through our guide on how to choose the best web design software, and the best WordPress landing page plugins.
我們希望本文能幫助您學習如何隱藏選擇性WordPress文章和頁面的標題。您還可以閱讀我們的指南,了解如何選擇最佳的網頁設計軟件和最佳的WordPress落地頁插件。
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.
如果您喜歡這篇文章,請訂閱我們的YouTube頻道,觀看WordPress視頻教程。您也可以在Twitter和Facebook上找到我們。
伙伴們,好幾天不見了,這一周菜鳥小白工作很忙,所以沒有每天更新學習內容,但是菜鳥小白的學習是沒有停下來的,只是沒有時間來整理學習筆記了。現在就將菜鳥小白這兩天學習的HTML基礎和大家分享,其中還會拿一些標簽進行舉例,顯示效果。
HTML語言是一種標簽語言,它不需要編譯,可以直接由瀏覽器執行。在標準網頁設計中HTML負責填充網頁的內容,HTML編寫的超文本文檔(文件)稱之為HTML文檔(網頁),它包含了一些html元素,使用html或者htm為文件名后綴,能獨立于各種操作系統平臺,如Unix、Windows等
標準的html文檔是由標簽和要顯示在網頁上的內容組成。HTML用于描述功能的符號成為“標簽”,如<html>、<body>、<table>等。HTML標簽規定HTML文檔的邏輯結構,并且控制文檔的顯示格式,然后由瀏覽器來負責解釋并顯示頁面。通過使用標簽可以區分文本文件的各個組成部分,對頁面上的文字、表格、圖片等多媒體數據所出現的位置、形式、順序及網頁間的超鏈接關系進行設定。
標簽都是封裝在一對尖括號“<……>”之中。標簽只改變網頁的顯示方式,本身不會顯示在窗口中。HTML文檔中最先出現的標簽是<html>標簽。<html>標簽是文檔標識符,它是成對出現的,首標簽<html>和尾標簽</html>分別位于文檔的最前面和最后面,明確地表示文檔是以超文本標識語言(HTML)編寫的。該標簽不帶任何屬性
<html>……</html>之間有如下標簽:
head是英文“頭”的意思。習慣上用戶把HTML文檔分為文檔頭和文檔主體兩部分。文檔主體部分就是在web瀏覽器窗口的用戶區內看到的內容,而文檔頭部分用來規定該文檔的標題(出現在web瀏覽器窗口的標題欄中)和文檔的一些屬性。<head>標簽對的作用就是控制文檔的頭部信息。中間可以使用<title>……</title>、<script>……</script>標簽對,在此標簽中間可以HTML文檔的標簽是可以嵌套的,即在一對標簽中可以嵌入另外一對子標簽,用來規定母標簽所含范圍的屬性或其中某一部分內容,嵌套在<head>……</head>標簽對中使用的主要有<title>標簽
<html lang="zh-cn">
<head>
<meta content="text/html;charset=utf-8">
菜鳥小白的學習分享
</head>
</html>
保存為HTML文件后顯示如下:
<title>標簽是成對出現的,用以規定HTML文檔的標題。在<title>……</title>之間的內容將顯示在web瀏覽器窗口的標題欄中。另外,<title>……</title>標簽對只能放在<head>……</head>標簽對之間,而且其內部不能包含其它標簽。
<html lang="zh-cn">
<head>
<meta content="text/html;charset=utf-8">
<title>菜鳥小白的學習分享</title>
</head>
</html>
修改后顯示如下:
<body>標簽也是成對出現的。在<body>……</body>之間的內容將顯示在web瀏覽器窗口的用戶區內,它是HTML文檔的主體部分。可以把HTML文檔的主體區域簡單地理解成標題以外的所有部分,該部分可以包含<table>、<font>、<img>、<div>等標簽。結束標簽</body>指明主體區域的結尾,在<body>中可以規定整個文檔的一些基本屬性:
我們驗證了前兩個屬性
<html lang="zh-cn">
<head>
<meta content="text/html;charset=utf-8">
<title>菜鳥小白的學習分享</title>
</head>
<body bgcolor="11ffff" text="000000">
測試內容
?
</body>
</html>
顯示效果如下:
在html中有許多特殊字符需要處理,例如:“<”、">"這兩個符號本身是用來表示標簽的開始和結束的,是沒有辦法通過直接打出來的,必須輸入編碼表示法:“<”和“>”。
通常情況下html會自動截取多余的空格。不管你加多少個空格,都被看做一個空格。如果要顯示多個空格,可以使用 表示空格
我們看看實現代碼
<html lang="zh-cn">
<head>
<meta content="text/html;charset=utf-8">
<title>菜鳥小白的學習分享</title>
</head>
?
<body bgcolor="11ffff" text="000000">
<測試內容> 空格在中間 看到了吧
?
</body>
</html>
顯示效果:
在瀏覽器中控制文本對象的顯示,包括段落、換行、水平線等標簽,下面介紹幾個常用的html格式標簽。所有的格式標簽全部都是在嵌套在<body>……</body>標簽對之間的
全稱paragraph。<p>……</p>標簽對用于創建一個段落,支持align屬性來設置對齊方式,語法如下:
<html lang="zh-cn">
<head>
<meta content="text/html;charset=utf-8">
<title>菜鳥小白的學習分享</title>
</head>
?
<body bgcolor="11ffff" text="000000">
<p align="center"><測試內容> 空格在中間 看到了吧</p>
?
</body>
</html>
顯示效果:
在不另起一段的情況下將當前文本強制換行,<br>標簽屬于單獨出現的標簽,禁止出現結束標簽。
<html lang="zh-cn">
<head>
<meta content="text/html;charset=utf-8">
<title>菜鳥小白的學習分享</title>
</head>
?
<body bgcolor="11ffff" text="000000">
<p align="center"><測試內容></br> 空格在中間 看到了吧</p>
?
</body>
</html>
顯示效果:
可以完整保留設計者在源文件中所定義的格式,包含各種空格,縮進,以及其他特殊字符,全部都原封不動的展示在瀏覽器頁面上。
<html lang="zh-cn">
<head>
<meta content="text/html;charset=utf-8">
<title>菜鳥小白的學習分享</title>
</head>
?
<body bgcolor="11ffff" text="000000">
<p align="center"><測試內容></br> 空格在中間 看到了吧</p>
<pre>
我是菜鳥小白
你們的好朋友
?
讓我們一起學習吧!!!
</pre>
?
</body>
</html>
顯示效果:
主要分為無序列表、排序列表、目錄列表、菜單列表和描述性列表五種類型
<html lang="zh-cn">
<head>
<meta content="text/html;charset=utf-8">
<title>菜鳥小白的學習分享</title>
</head>
?
<body bgcolor="11ffff" text="000000">
<ul>
<li>我是菜鳥小白</li>
<li>你們的好朋友</li>
?
<li> 讓我們一起學習吧!!!</li>
</ul>
?
</body>
</html>
效果如下:
?描述性列表:
<html lang="zh-cn">
<head>
<meta content="text/html;charset=utf-8">
<title>菜鳥小白的學習分享</title>
</head>
?
<body bgcolor="11ffff" text="000000">
<dl>
<dt>菜鳥小白測試表頭</dt>
<dd>我是菜鳥小白</dd>
<dd>你們的好朋友</dd>
<dd> 讓我們一起學習吧!!!</dd>
<dt>菜鳥小白測試表頭2</dt>
<dd>我是菜鳥小白</dd>
<dd>你們的好朋友</dd>
<dd> 讓我們一起學習吧!!!</dd>
</dl>
?
</body>
</html>
顯示效果如下:
?
好了,今天的內容就到這了,我們明天繼續學習HTML基礎內容,不見不散~
少時候,一篇文章能否得到廣泛的傳播,除了文章本身實打實的質量以外,一個好的標題也至關重要。本文爬取了虎嗅網建站至今共 5 萬條新聞標題內容,助你找到起文章標題的技巧與靈感。同時,分享一些值得關注的文章和作者。
寫在前面:由于文中有一些超鏈接,無法在公眾號打開,建議點擊底部「閱讀原文」或者復制下面的博客鏈接到瀏覽器打開,體驗更好。https://www.makcyun.top/
在眾多新媒體網站中,「虎嗅」網的文章內容和質量還算不錯。在「新榜」科技類公眾號排名中,它位居榜單第 3 名,還是比較受歡迎的。所以選擇爬取該網站的文章信息,順便從中了解一下這幾年科技互聯網都出現了哪些熱點信息。
「關于虎嗅」虎嗅網創辦于 2012 年 5 月,是一個聚合優質創新信息與人群的新媒體平臺。該平臺專注于貢獻原創、深度、犀利優質的商業資訊,圍繞創新創業的觀點進行剖析與交流。虎嗅網的核心,是關注互聯網及傳統產業的融合、明星公司的起落軌跡、產業潮汐的動力與趨勢。
使用 pyspider 抓取了虎嗅網的主頁文章,文章抓取時期為 2012 年建站至 2018 年 11 月 1 日,共計約 5 萬篇文章。抓取 了 7 個字段信息:文章標題、作者、發文時間、評論數、收藏數、摘要和文章鏈接。
這是要爬取的 網頁界面,可以看到是通過 AJAX 加載的。
右鍵打開開發者工具查看翻頁規律,可以看到 URL 請求是 POST 類型,下拉到底部查看 Form Data,表單需提交參數只有 3 項。經嘗試, 只提交 page 參數就能成功獲取頁面的信息,其他兩項參數無關緊要,所以構造分頁爬取非常簡單。
接著,切換選項卡到 Preview 和 Response 查看網頁內容,可以看到數據都位于 data 字段里。total_page 為 2004,表示一共有 2004 頁的文章內容,每一頁有 25 篇文章,總共約 5 萬篇,也就是我們要爬取的數量。
以上,我們就找到了所需內容,接下來可以開始構造爬蟲,整個爬取思路比較簡單。之前我們也練習過這一類 Ajax 文章的爬取,可以參考:
做 PPT 沒靈感?澎湃網 1500 期信息圖送給你
和之前文章不同的是,這里我們使用一種新的工具來進行爬取,叫做:pyspider 框架。由國人 binux 大神開發,GitHub Star 數超過 12 K,足以證明它的知名度。可以說,學習爬蟲不能不會使用這個框架。
網上關于這個框架的介紹和實操案例非常多,這里僅簡單介紹一下。
我們之前的爬蟲都是在 Sublime 、PyCharm 這種 IDE 窗口中執行的,整個爬取過程可以說是處在黑箱中,內部運行的些細節并不太清楚。而 pyspider 一大亮點就在于提供了一個可視化的 WebUI 界面,能夠清楚地查看爬蟲的運行情況。
pyspider 的架構主要分為 Scheduler(調度器)、Fetcher(抓取器)、Processer(處理器)三個部分。Monitor(監控器)對整個爬取過程進行監控,Result Worker(結果處理器)處理最后抓取的結果。
該框架比較容易上手,網頁右邊是代碼區,先定義類(Class)然后在里面添加爬蟲的各種方法(也可以稱為函數),運行的過程會在左上方顯示,左下方則是輸出結果的區域。
這里,分享幾個不錯的教程以供參考:
安裝好該框架并大概了解用法后,下面我們可以就開始爬取了。
CMD 命令窗口執行:pyspider all 命令,然后瀏覽器輸入:http://localhost:5000/ 就可以啟動 pyspider 。
點擊 Create 新建一個項目,Project Name 命名為:huxiu,因為要爬取的 URL 是 POST 類型,所以這里可以先不填寫,之后可以在代碼中添加,再次點擊 Creat 便完成了該項目的新建。
新項目建立好后會自動生成一部分模板代碼,我們只需在此基礎上進行修改和完善,然后就可以運行爬蟲項目了。現在,簡單梳理下代碼編寫步驟。
這里,首先定義了一個 Handler 主類,整個爬蟲項目都主要在該類下完成。 接著,可以將爬蟲基本的一些基本配置,比如:Headers、代理等設置寫在下面的 crawl_config 屬性中。
如果你還沒有習慣從函數(def)轉換到類(Class)的代碼寫法,那么需要先了解一下類的相關知識,之后我也會單獨用一篇文章介紹一下。
下面的 on_start 方法是程序的入口,也就是說程序啟動后會首先從這里開始運行。首先,我們將要爬取的 URL傳入 crawl 方法,同時將 URL 修改成虎嗅網的:https://www.huxiu.com/v2_action/article_list。
由于 URL 是 POST 請求,所以我們還需要增加兩個參數:method 和 data。method 表示 HTTP 請求方式,默認是 GET,這里我們需要設置為 POST;data 是 POST 請求表單參數,只需要添加一個 page 參數即可。
接著,通過 callback 參數定義一個 index_page 方法,用來解析 crawl 方法爬取 URL 成功后返回的 Response 響應。在后面的 index_page 方法中,可以使用 PyQuery 提取響應中的所需內容。
具體提取方法如下:
這里,網頁返回的 Response 是 json 格式,待提取的信息存放在其中的 data 鍵值中,由一段 HTML 代碼構成。我們可以使用 response.json[‘data’] 獲取該 HTML 信息,接著使用 PyQuery 搭配 CSS 語法提取出文章標題、鏈接、作者等所需信息。這里使用了列表生成式,能夠精簡代碼并且轉換為方便的 list 格式,便于后續存儲到 MongoDB 中。
可以看到,成功得到所需數據,然后就可以保存了,可以選擇輸出為 CSV、MySQL、MongoDB 等方式,這里我們選擇保存到 MongoDB 中。
上面,定義了一個 on_result 方法,該方法專門用來獲取 return 的結果數據。這里用來接收上面 index_page 返回的 data 數據,在該方法里再定義一個存儲到 MongoDB 的方法就可以保存到 MongoDB 中。
關于數據如何存儲到 MongoDB 中,我們在之前的一篇文章中有過介紹,如果忘記了可以回顧一下。
下面,我們來測試一下整個爬取和存儲過程。點擊左上角的 run 就可以順利運行單個網頁的抓取、解析和存儲,結果如下:
上面完成了單頁面的爬取,接下來,我們需要爬取全部 2000 余頁內容。
需要修改兩個地方,首先在 on_start 方法中將 for 循環頁數 3 改為 2002。改好以后,如果我們直接點擊 run ,會發現還是只能爬取第 2 頁的結果。
這是因為,pyspider 以 URL的 MD5 值作為 唯一 ID 編號,ID 編號相同的話就視為同一個任務,便不會再重復爬取。由于 GET 請求的 分頁URL 通常是有差異的,所以 ID 編號會不同,也就自然能夠爬取多頁。但這里 POST 請求的分頁 URL 是相同的,所以爬完第 2 頁,后面的頁數便不會再爬取。
那有沒有解決辦法呢? 當然是有的,我們需要重新寫下 ID 編號的生成方式,方法很簡單,在 on_start 方法前面添加下面 2 行代碼即可:
這樣,我們再點擊 run 就能夠順利爬取 2000 頁的結果了,我這里一共抓取了 49,996 條結果,耗時 2 小時左右完成。
以上,就完成了數據的獲取。有了數據我們就可以著手分析,不過這之前還需簡單地進行一下數據的清洗、處理。
首先,我們需要從 MongoDB 中讀取數據,并轉換為 DataFrame。
下面我們看一下數據的總體情況,可以看到數據的維度是 49996 行 × 8 列。發現多了一列無用的 _id 需刪除,同時 name 列有一些特殊符號,比如? 需刪除。另外,數據格式全部為 Object 字符串格式,需要將 comment 和 favorites 兩列更改為數值格式、 write_time 列更改為日期格式。
代碼實現如下:
下面,我們看一下數據是否有重復,如果有,那么需要刪除。
然后,我們再增加兩列數據,一列是文章標題長度列,一列是年份列,便于后面進行分析。
以上,就完成了基本的數據清洗處理過程,針對這 9 列數據可以開始進行分析了。
通常,數據分析主要分為四類: 「描述型分析」、「診斷型分析」、「預測型分析」、「規范型分析」。
「描述型分析」是用來概括、表述事物整體狀況以及事物間關聯、類屬關系的統計方法,是這四類中最為常見的數據分析類型。通過統計處理可以簡潔地用幾個統計值來表示一組數據地集中性(如平均值、中位數和眾數等)和離散型(反映數據的波動性大小,如:方差、標準差等。)
這里,我們主要進行描述性分析,數據主要為數值型數據(包括離散型變量和連續型變量)和文本數據。
先來看一下總體情況:
這里,使用了 data.describe 方法對數值型變量進行統計分析。從上面可以簡要得出以下幾個結論:
對于非數值型變量(name、write_time),使用 describe 方法會產生另外一種匯總統計。
unique 表示唯一值數量,top 表示出現次數最多的變量,freq 表示該變量出現的次數,所以可以簡單得出以下幾個結論:
可以看到 ,以季度為時間尺度的 6 年間,前幾年發文數量比較穩定,大概在1750 篇左右,個別季度數量激增到 2000 篇以上。2016 年之后文章開始增加到 2000 篇以上,可能跟網站知名度提升有關。首尾兩個季度日期不全,所以數量比較少。
具體代碼實現如下:
接下來,到了我們比較關心的問題:幾萬篇文章里,到底哪些文章寫得比較好或者比較火?
此處選取了「favorites」作為衡量標準。畢竟,一般好的文章,我們都會有收藏的習慣。
第一名「讀完這10本書,你就能站在智商鄙視鏈的頂端了 」以 1113 次收藏位居第一,并且遙遙領先于后者,看來大家都懷有「想早日攀上人生巔峰,一覽眾人小」的想法啊。打開這篇文章的鏈接,文中提到了這幾本書:《思考,快與慢》、《思考的技術》、《麥肯錫入職第一課:讓職場新人一生受用的邏輯思考力》等。一本都沒看過,看來這輩子是很難登上人生巔峰了。
發現兩個有意思的地方:第一,文章標題都比較短小精煉。第二,文章收藏量雖然比較高,但評論數都不多,猜測這是因為——大家都喜歡做伸手黨?
在了解文章的總體排名之后,我們來看看歷年的文章排名是怎樣的。這里,每年選取了收藏量最多的 3 篇文章。
可以看到,文章收藏量基本是逐年遞增的,但 2015 年的 3 篇文章的收藏量卻是最高的,包攬了總排名的前 3 名,不知道這一年的文章有什么特別之處。
以上只羅列了一小部分文章的標題,可以看到標題起地都蠻有水準的。關于標題的重要性,有這樣通俗的說法:「一篇好文章,標題占一半」,一個好的標題可以大大增強文章的傳播力和吸引力。文章標題雖只有短短數十字,但要想起好,里面也是很有很多技巧的。
好在,這里提供了 5 萬個標題可供參考。代碼實現如下:
上面,我們從收藏量指標進行了分析,下面,我們關注一下發布文章的作者(個人/媒體)。前面提到發文最多的是虎嗅官方,有一萬多篇文章,這里我們篩除官媒,看看還有哪些比較高產的作者。
可以看到,前 20 名作者的發文量差距都不太大。發文比較多的有「娛樂資本論」、「Eastland」、「發條橙子」這類媒體號;也有虎嗅官網團隊的作者:發條橙子、周超臣、張博文等;還有部分獨立作者:假裝FBI、孫永杰等。可以嘗試關注一下這些高產作者。
代碼實現如下:
我們關注一個作者除了是因為文章高產以外,可能更看重的是其文章水準。這里我們選擇「文章平均收藏量」(總收藏量/文章數)這個指標,來看看文章水準比較高的作者是哪些人。
這里,為了避免出現「某作者只寫了一篇高收藏率的文章」這種不能代表其真實水準的情況,我們將篩選范圍定在至少發布過 5 篇文章的作者們。
可以看到,前 10 名作者包括:遙遙領先的 重讀、兩位高產又有質量的辯手李慕陽和飯統戴老板,還有大眾比較熟悉的高曉松、寧南山等。
如果你將這份名單和上面那份高產作者名單進行對比,會發現他們沒有出現在這個名單中。相比于數量,質量可能更重要吧。
下面,我們就來看看排名第一的 重讀都寫了哪些高收藏量文章。
居然寫的都是清一色關于馬老板家的文章。
了解了前十名作者之后,我們順便也看看那些處于最后十名的都是哪些作者。
一對比,就能看到他們的文章收藏量就比較寒磣了。尤其好奇最后一位作者 Yang Yemeng,他寫了 7 篇文章,竟然一個收藏都沒有。
來看看他究竟寫了些什么文章。
原來寫的全都是英文文章,看來大家并不太鐘意閱讀英文類的文章啊。
具體實現代碼:
說完了收藏量。下面,我們再來看看評論數量最多的文章是哪些。
基本上都是和 三星有關的文章,這些文章大多來自 2014 年,那幾年三星好像是挺火的,不過這兩年國內基本上都見不到三星的影子了,世界變化真快。
發現了兩個有意思的現象。
我們進一步觀察下這兩個參數的關系。
可以看到,大多數點都位于左下角,意味著這些文章收藏量和評論數都比較低。但也存在少部分位于上方和右側的異常值,表明這些文章呈現 「多評論、少收藏」或者「少評論、多收藏」的特點。
下面,我們再來看看文章標題的長度和收藏量之間有沒有什么關系。
大致可以看出兩點現象:
看來,文章起標題時最好不要起太長的。
實現代碼如下:
下面,我們看看作者在起文章標題的時候,在標點符號方面有沒有什么偏好。
可以看到,五萬篇文章中,大多數文章的標題是陳述性標題。三分之一(34.8%) 的文章標題使用了問號「?」,而僅有 5% 的文章用了嘆號「!」。通常,問號會讓人們產生好奇,從而想去點開文章;而嘆號則會帶來一種緊張或者壓迫感,使人不太想去點開。所以,可以嘗試多用問號而少用嘆號。
最后,我們從這 5 萬篇文章中的標題和摘要中,來看看虎嗅網的文章主要關注的都是哪些主題領域。
這里首先運用了 jieba 分詞包對標題進行了分詞,然后用 WordCloud 做成了詞云圖,因虎嗅網含有「虎」字,故選取了一張老虎頭像。(關于 jieba 和 WordCloud 兩個包,之后再詳細介紹)
可以看到文章的主題內容側重于:互聯網、知名公司、電商、投資這些領域。這和網站本身對外宣傳的核心內容,即「關注互聯網與移動互聯網一系列明星公司的起落軌跡、產業潮汐的動力與趨勢,以及互聯網與移動互聯網如何改造傳統產業」大致相符合。
實現代碼如下:
上面的關鍵詞是這幾年總體的概況,而科技互聯網行業每年的發展都是不同的,所以,我們再來看看歷年的一些關鍵詞,透過這些關鍵詞看看這幾年互聯網行業、科技熱點、知名公司都有些什么不同變化。
可以看到每年的關鍵詞都有一些相同之處,但也不同的地方:
通過這一幅圖,就看出了這幾年科技互聯網行業、明星公司、熱點信息的風云變化。
本文完。
作者:蘇克1900,公眾號:第2大腦(ID:Mocun6)
*請認真填寫需求信息,我們會在24小時內與您取得聯系。