一群棒子
  • 首頁
  • 作者
  • 關於我們
Tagged

Shortcode

A collection of 2 posts

WordPress 中 is_home() 與 is_front_page() 的差異
WordPress

WordPress 中 is_home() 與 is_front_page() 的差異

當我們在開發自己的 theme 時,常需要針對判斷當前頁面是否為首頁,這件事情來做相對應的判斷,舉個例子 <body class ="<?php is_home() ? print 'front' : print 'not-front'; ?>"> //balabala </body> 判斷當前是否為首頁並在 body 的元素上給上想要的 class 方便我們寫 CSS 樣式,可是設定為首頁卻得到 not-front 實在讓人疑問,難道是 BUG 嗎 > 在這裡使用 PHP if() 條件式的簡寫 可以參考PHP: if [http:

  • jimmy8646
jimmy8646 2017年4月30日 • 2 min read
WordPress

【WordPress筆記】 利用shortcode 的方式將指定的post type 文章顯示在頁面中

前言 當WordPress頁面都是用shortcode疊出來的時候,你的文章(post)也是需要變成shortcode的情況下才有辦法將它卡到頁面的某個地方,以下方式可以將你的文章(post)轉成shortcode的方式,讓你在頁面中可以方便的調用它!! 以下範例code,可以寫至theme目錄下的functions.php中 function home_post_listing_shortcode( $atts ) { ob_start(); <!--將query 到的資料存到$query--> $query = new WP_Query( array( 'post_type' => 'post', <!--post_type輸入你想要抓取的文章類型--> 'posts_per_page' => 3, <

  • pig
pig 2017年4月28日 • 2 min read
一群棒子 © 2025
Powered by Ghost