2014-02-19 154 views
0

使用此代碼如何將內容標題添加到內容描述中?

<?php 
$post = $wp_query->post; 
$descrip = strip_tags($post->post_content); 
$descrip_more = ''; 
if (strlen($descrip) > 155) { 
$descrip = substr($descrip,0,155); 
$descrip_more = ' ...'; 
} 
$descrip = str_replace('"', '', $descrip); 
$descrip = str_replace("'", '', $descrip); 
$descripwords = preg_split('/[\n\r\t ]+/', $descrip, -1, PREG_SPLIT_NO_EMPTY); 
array_pop($descripwords); 
$descrip = implode(' ', $descripwords) . $descrip_more; $descrip = strip_shortcodes($descrip); 
echo '<meta name="description" content="'.$descrip.'">'; ?> 

這在我的頭輸出是這樣的:

<meta name="description" content=" Everything year life dont know why but ..."> 

我在想,如果我可以添加的東西會在「一切之前添加單個帖子標題代碼一年的生活不知道爲什麼,但......「的一部分,在內容的開始,所以它看起來像

也許這樣吧?

<meta name="description" content=" Uverworld - nano second (<-- the post title) Everything year life dont know why but  ..."> 
換句話說

<meta name="description" content=" Uverworld - nano second Everything year life dont know why but  ..."> 

-

上面的代碼也留下了很多的空間內容之前,顯示像 有沒有辦法擺脫的那個以及?

+0

爲什麼不把文章標題中''元素? – <span class="text-secondary"> <small> <span></span> </small> </span> </p> </div> </div> </div> <div itemprop="comment" class="post-comment"> <div class="row"> <div class="col-lg-1"><span class="text-secondary">+0</span></div> <div class="col-lg-11"> <p class="commenttext">它已經在那裏了,但是對於搜索引擎優化的目的,我試圖在標題和說明的描述中進行組合。 – <span class="text-secondary"> <small> <a rel="noopener" target="_blank" href="https://stackoverflow.com/users/2320262/">user2320262</a></span> <span></span> </small> </span> </p> </div> </div> </div> <div itemprop="comment" class="post-comment"> <div class="row"> <div class="col-lg-1"><span class="text-secondary">+0</span></div> <div class="col-lg-11"> <p class="commenttext">你爲什麼認爲這將有助於搜索引擎優化? – <span class="text-secondary"> <small> <span></span> </small> </span> </p> </div> </div> </div> </div> </div> </article> </div> <div class="answer-title"> <span class="text-logo margin-top-sm">A</span> <h2 class="title h4">回答</h2> </div> <div class="item-description text-md markdown-body margin-bottom-40 voidso"> <article class="board-top-1 padding-top-10"> <div class="post-col vote-info"> <span class="count">0<i class="fa fa-thumbs-up"></i></span> </div> <div class="post-offset"> <div class="answer fmt"> <p>你可以做到以下幾點:</p> <pre><code class="prettyprint-override"><meta name="description" content="<?php echo get_the_title(); ?> Everything year life dont know why but ..."> </code></pre> </div> <div class="post-info"> <div class="post-meta row"> <p class="text-secondary col-lg-6"> <span class="source"> <a rel="noopener" target="_blank" href="https://stackoverflow.com/q/21903214">來源</a> </span> </p> <p class="text-secondary col-lg-6"> <span class="float-right date"> <span>2014-02-20 09:16:43</span> <a rel="noopener" target="_blank" href="https://stackoverflow.com/users/1214660/">danyo</a></span> </p> <p class="col-12"></p> <p class="col-12"></p></div> </div> </div> </article> <div> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-6208739752673518" data-ad-slot="1038284119" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> <div class="clearfix"> </div> <div class="relative-box"> <div class="relative">相關問題</div> <ul class="relative_list"> <li> 1. <a href="http://hk.uwenku.com/question/p-xuoumlyf-te.html" target="_blank" title="如何在列表標題內容Wordpress中添加描述編號?"> 如何在列表標題內容Wordpress中添加描述編號? </a> </li> <li> 2. <a href="http://hk.uwenku.com/question/p-xamdunjw-cs.html" target="_blank" title="將內容添加到內容區域"> 將內容添加到內容區域 </a> </li> <li> 3. <a href="http://hk.uwenku.com/question/p-eebqfwzy-bnb.html" target="_blank" title="Pjax:將內容添加到內容"> Pjax:將內容添加到內容 </a> </li> <li> 4. <a href="http://hk.uwenku.com/question/p-hwjpaasx-vg.html" target="_blank" title="Rails描述HTML內容源"> Rails描述HTML內容源 </a> </li> <li> 5. <a href="http://hk.uwenku.com/question/p-gjqvuapf-u.html" target="_blank" title="將內容添加到模板標記"> 將內容添加到模板標記 </a> </li> <li> 6. <a href="http://hk.uwenku.com/question/p-akfrduax-cv.html" target="_blank" title="將內容添加到webview?"> 將內容添加到webview? </a> </li> <li> 7. <a href="http://hk.uwenku.com/question/p-eehfpcaf-gk.html" target="_blank" title="將內容添加到UIScrollView"> 將內容添加到UIScrollView </a> </li> <li> 8. <a href="http://hk.uwenku.com/question/p-seueggfu-bkb.html" target="_blank" title="將內容添加到UserControl"> 將內容添加到UserControl </a> </li> <li> 9. <a href="http://hk.uwenku.com/question/p-ojosyplg-bed.html" target="_blank" title="將內容添加到umbraco?"> 將內容添加到umbraco? </a> </li> <li> 10. <a href="http://hk.uwenku.com/question/p-ynpfajfu-so.html" target="_blank" title="元標題/描述/關鍵字內容中的轉義字符"> 元標題/描述/關鍵字內容中的轉義字符 </a> </li> <div> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-6208739752673518" data-ad-slot="4606349252"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <li> 11. <a href="http://hk.uwenku.com/question/p-hmoqzcmi-dq.html" target="_blank" title="如何將新內容添加到td"> 如何將新內容添加到td </a> </li> <li> 12. <a href="http://hk.uwenku.com/question/p-gveeazrz-bcn.html" target="_blank" title="如何將ControlTemplate添加到內容?"> 如何將ControlTemplate添加到內容? </a> </li> <li> 13. <a href="http://hk.uwenku.com/question/p-btryzumw-gr.html" target="_blank" title="如何將Rx.Observable.fromEvent添加到ajax內容"> 如何將Rx.Observable.fromEvent添加到ajax內容 </a> </li> <li> 14. <a href="http://hk.uwenku.com/question/p-efwpctls-sa.html" target="_blank" title="如何將內容添加到回覆?"> 如何將內容添加到回覆? </a> </li> <li> 15. <a href="http://hk.uwenku.com/question/p-ubxrrvyb-h.html" target="_blank" title="div中的內容作爲元描述"> div中的內容作爲元描述 </a> </li> <li> 16. <a href="http://hk.uwenku.com/question/p-ukyjyjpd-cw.html" target="_blank" title="圖片按鈕中的內容描述"> 圖片按鈕中的內容描述 </a> </li> <li> 17. <a href="http://hk.uwenku.com/question/p-nlhyhfma-bnx.html" target="_blank" title="如何將add_filter添加到插件後添加到內容中"> 如何將add_filter添加到插件後添加到內容中 </a> </li> <li> 18. <a href="http://hk.uwenku.com/question/p-klelowio-bcy.html" target="_blank" title="ASP.NET AJAX Toolkit不斷將新內容添加到舊內容中"> ASP.NET AJAX Toolkit不斷將新內容添加到舊內容中 </a> </li> <li> 19. <a href="http://hk.uwenku.com/question/p-vnamtskv-bv.html" target="_blank" title="將內容加載到DIV標記中,內容從"> 將內容加載到DIV標記中,內容從 </a> </li> <li> 20. <a href="http://hk.uwenku.com/question/p-eujupmni-bex.html" target="_blank" title="Dyanamically標籤內容添加問題"> Dyanamically標籤內容添加問題 </a> </li> <li> 21. <a href="http://hk.uwenku.com/question/p-rvjmbpue-bbr.html" target="_blank" title="將內容描述設置爲圖像按鈕的問題"> 將內容描述設置爲圖像按鈕的問題 </a> </li> <li> 22. <a href="http://hk.uwenku.com/question/p-bprbhawj-bs.html" target="_blank" title="加載內容到標題從標籤"> 加載內容到標題從標籤 </a> </li> <li> 23. <a href="http://hk.uwenku.com/question/p-thxceaga-kw.html" target="_blank" title="如何添加標題到內容頁編程xamarin形式?"> 如何添加標題到內容頁編程xamarin形式? </a> </li> <li> 24. <a href="http://hk.uwenku.com/question/p-ditdkwvy-uq.html" target="_blank" title="將內容添加到數據庫中"> 將內容添加到數據庫中 </a> </li> <li> 25. <a href="http://hk.uwenku.com/question/p-ffmdfqtr-ec.html" target="_blank" title="將內容添加到wordpress中的tinyMCE"> 將內容添加到wordpress中的tinyMCE </a> </li> <li> 26. <a href="http://hk.uwenku.com/question/p-gmplbvrl-ca.html" target="_blank" title="添加內容問題"> 添加內容問題 </a> </li> <li> 27. <a href="http://hk.uwenku.com/question/p-acbwdhlv-bh.html" target="_blank" title="Handlerbarjs:如何額外的內容添加到{{#each}}內容"> Handlerbarjs:如何額外的內容添加到{{#each}}內容 </a> </li> <li> 28. <a href="http://hk.uwenku.com/question/p-gqtldkgd-eg.html" target="_blank" title="將整個標題內容添加到Doxygen組"> 將整個標題內容添加到Doxygen組 </a> </li> <li> 29. <a href="http://hk.uwenku.com/question/p-xcwbqjdh-ha.html" target="_blank" title="離子按鈕內容描述"> 離子按鈕內容描述 </a> </li> <li> 30. <a href="http://hk.uwenku.com/question/p-fpmflpbs-bo.html" target="_blank" title="如何將域名,網站標題等內容添加到代碼中?"> 如何將域名,網站標題等內容添加到代碼中? </a> </li> </ul> </div> <div> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-6208739752673518" data-ad-slot="1575177025"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <div class="padding-top-10"></div> </div> </div> <script type="text/javascript" src="http://img.uwenku.com/uwenku/script/side.js?t=1644592048261"></script> <script type="text/javascript" src="http://img.uwenku.com/uwenku/plugin/highlight/highlight.pack.js"></script> <link href="http://img.uwenku.com/uwenku/plugin/highlight/styles/docco.css" media="screen" rel="stylesheet" type="text/css" /> <script type="text/javascript"> $('pre').each(function(i, e) { hljs.highlightBlock(e, "<span class='indent'> </span>", false) }); </script> <div class="col-lg-3 col-md-4 col-sm-5"> <div id="rightTop"> <div class="row"> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-6208739752673518" data-ad-slot="5415218910" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <div class="row sidebar panel panel-default"> <div class="panel-heading font-bold"> 最新問題 </div> <div class="m-b-sm m-t-sm clearfix"> <ul class="side_article_list"> <li class="side_article_list_item"> 1. <a href="http://hk.uwenku.com/question/p-tvgmrvpy-hb.html" target="_blank" title="Spyder 3.1.4 - 操作系統升級後無法配置Spyder"> Spyder 3.1.4 - 操作系統升級後無法配置Spyder </a> </li> <li class="side_article_list_item"> 2. <a href="http://hk.uwenku.com/question/p-nrnjrlra-kr.html" target="_blank" title="能從應用程序的BeginRequest在第一次請求使用RewritePath"> 能從應用程序的BeginRequest在第一次請求使用RewritePath </a> </li> <li class="side_article_list_item"> 3. <a href="http://hk.uwenku.com/question/p-xyxztndm-hw.html" target="_blank" title="如何使用帶空格的HTML Git Diff?"> 如何使用帶空格的HTML Git Diff? </a> </li> <li class="side_article_list_item"> 4. <a href="http://hk.uwenku.com/question/p-fsgdmwpl-eb.html" target="_blank" title="如何使用setActiveItem進行卡片佈局以基於radiobuttton選擇顯示面板?"> 如何使用setActiveItem進行卡片佈局以基於radiobuttton選擇顯示面板? </a> </li> <li class="side_article_list_item"> 5. <a href="http://hk.uwenku.com/question/p-zcmykspd-dh.html" target="_blank" title="爲什麼如果(a!= 65)沒有執行?"> 爲什麼如果(a!= 65)沒有執行? </a> </li> <li class="side_article_list_item"> 6. <a href="http://hk.uwenku.com/question/p-vdmsgred-ex.html" target="_blank" title="字符串中最後2個括號之間的所有大寫字母的正則表達式"> 字符串中最後2個括號之間的所有大寫字母的正則表達式 </a> </li> <li class="side_article_list_item"> 7. <a href="http://hk.uwenku.com/question/p-fricngen-z.html" target="_blank" title="由不同的解決方案調用的一個共享項目中的JS文件"> 由不同的解決方案調用的一個共享項目中的JS文件 </a> </li> <li class="side_article_list_item"> 8. <a href="http://hk.uwenku.com/question/p-aiwiznwb-d.html" target="_blank" title="Java 8 DateTimeFormatterBuilder()。appendOptional不工作"> Java 8 DateTimeFormatterBuilder()。appendOptional不工作 </a> </li> <li class="side_article_list_item"> 9. <a href="http://hk.uwenku.com/question/p-eoqvbwzw-cc.html" target="_blank" title="傳數據從小孩到在母體陣營節目類型錯誤"> 傳數據從小孩到在母體陣營節目類型錯誤 </a> </li> <li class="side_article_list_item"> 10. <a href="http://hk.uwenku.com/question/p-pjpbavcz-bmd.html" target="_blank" title="谷歌附近的通知分析"> 谷歌附近的通知分析 </a> </li> </ul> </div> </div> </div> <p class="article-nav-bar"></p> <div class="row sidebar article-nav"> <div class="row box_white visible-sm visible-md visible-lg margin-zero"> <div class="top"> <h3 class="title"><i class="glyphicon glyphicon-th-list"></i> 相關問題</h3> </div> <div class="article-relative-content"> <ul class="side_article_list"> <li class="side_article_list_item"> 1. <a href="http://hk.uwenku.com/question/p-xuoumlyf-te.html" target="_blank" title="如何在列表標題內容Wordpress中添加描述編號?"> 如何在列表標題內容Wordpress中添加描述編號? </a> </li> <li class="side_article_list_item"> 2. <a href="http://hk.uwenku.com/question/p-xamdunjw-cs.html" target="_blank" title="將內容添加到內容區域"> 將內容添加到內容區域 </a> </li> <li class="side_article_list_item"> 3. <a href="http://hk.uwenku.com/question/p-eebqfwzy-bnb.html" target="_blank" title="Pjax:將內容添加到內容"> Pjax:將內容添加到內容 </a> </li> <li class="side_article_list_item"> 4. <a href="http://hk.uwenku.com/question/p-hwjpaasx-vg.html" target="_blank" title="Rails描述HTML內容源"> Rails描述HTML內容源 </a> </li> <li class="side_article_list_item"> 5. <a href="http://hk.uwenku.com/question/p-gjqvuapf-u.html" target="_blank" title="將內容添加到模板標記"> 將內容添加到模板標記 </a> </li> <li class="side_article_list_item"> 6. <a href="http://hk.uwenku.com/question/p-akfrduax-cv.html" target="_blank" title="將內容添加到webview?"> 將內容添加到webview? </a> </li> <li class="side_article_list_item"> 7. <a href="http://hk.uwenku.com/question/p-eehfpcaf-gk.html" target="_blank" title="將內容添加到UIScrollView"> 將內容添加到UIScrollView </a> </li> <li class="side_article_list_item"> 8. <a href="http://hk.uwenku.com/question/p-seueggfu-bkb.html" target="_blank" title="將內容添加到UserControl"> 將內容添加到UserControl </a> </li> <li class="side_article_list_item"> 9. <a href="http://hk.uwenku.com/question/p-ojosyplg-bed.html" target="_blank" title="將內容添加到umbraco?"> 將內容添加到umbraco? </a> </li> <li class="side_article_list_item"> 10. <a href="http://hk.uwenku.com/question/p-ynpfajfu-so.html" target="_blank" title="元標題/描述/關鍵字內容中的轉義字符"> 元標題/描述/關鍵字內容中的轉義字符 </a> </li> </ul> </div> </div> </div> </div> </div> </div> </div><!-- wrap end--> <!-- footer --> <footer id="footer"> <div class="bg-simple lt"> <div class="container"> <div class="row padder-v m-t"> <div class="col-xs-8"> <ul class="list-inline"> <li><a href="http://hk.uwenku.com/contact">聯系我們</a></li> <li>© 2020 HK.UWENKU.COM</li> <li><a target="_blank" href="https://beian.miit.gov.cn/">沪ICP备13005482号-4</a></li> <li><script type="text/javascript" src="https://v1.cnzz.com/z_stat.php?id=1280101193&web_id=1280101193"></script></li> <li><a href="http://www.uwenku.com/" target="_blank" title="优文库">简体中文</a></li> <li><a href="http://hk.uwenku.com/" target="_blank" title="優文庫">繁體中文</a></li> <li><a href="http://ru.uwenku.com/" target="_blank" title="поле вопросов и ответов">Русский</a></li> <li><a href="http://de.uwenku.com/" target="_blank" title="Frage - und - antwort - Park">Deutsch</a></li> <li><a href="http://es.uwenku.com/" target="_blank" title="Preguntas y respuestas">Español</a></li> <li><a href="http://hi.uwenku.com/" target="_blank" title="कार्यक्रम प्रश्न और उत्तर पार्क">हिन्दी</a></li> <li><a href="http://it.uwenku.com/" target="_blank" title="IL Programma di chiedere Park">Italiano</a></li> <li><a href="http://ja.uwenku.com/" target="_blank" title="プログラム問答園区">日本語</a></li> <li><a href="http://ko.uwenku.com/" target="_blank" title="프로그램 문답 단지">한국어</a></li> <li><a href="http://pl.uwenku.com/" target="_blank" title="program o park">Polski</a></li> <li><a href="http://tr.uwenku.com/" target="_blank" title="Program soru ve cevap parkı">Türkçe</a></li> <li><a href="http://vi.uwenku.com/" target="_blank" title="Đáp ứng viên">Tiếng Việt</a></li> <li><a href="http://fr.uwenku.com/" target="_blank" title="Programme interrogation Park">Française</a></li> </ul> </div> </div> </div> </div> </div> </footer> <!-- / footer --> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?f78a970f17b19a79fc477a3378096f29"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </body> </html>