
內容簡介
在 interconnect/it,我們的開發客戶網站的方針是「全內容管理!」這表示網站上的小提示、小工具等不僅要進行內容管理,而且它們對於終端使用者和開發人員來說都應該易於處理。
因此,我們開發了 Spots。這將創建一個自定義文章類型,使您可以使用視覺編輯器創建小工具,同時還為主題中的內容管理元素創建了一個易於使用的鉤子。
現在,此外掛使用快取以幫助確保 typyal 網站上的負載保持最小。性能很重要!
此外掛已準備好進行翻譯,如果您想向我們提交翻譯,可以通過我們的網站聯繫我們。
開發人員注意事項
Spots 為開發人員提供了 2 個模板標籤,具體如下:
icit_spot( $id_or_name, $template );
$id_or_name:必填,數字 ID 或字符串形式的スポット名。
$template:可選,String 用於調用 get_template_part()
此模板標籤始終會顯示出該小工具。
icit_get_spot( $id_or_name, $template, $echo );
與上述相同,但帶有一個額外的參數:
$echo:可選,預設為 false。布林值,指示是輸出還是只返回小工具內容。
一般用法
您可以使用 Spots 替換主題中的樣板文本。如果您在主題中有區域通常要硬編碼文本,您可以使用以下代碼:
<?php
if ( function_exists( 'icit_spot' ) )
icit_spot( 'Copyright' );
?>
上述代碼會輸出標題為「Copyright」的小工具內容。如果該小工具不存在,則會以草稿形式創建。草稿模式下的小工具僅對帶有編輯功能的已登錄用戶可見。
模板
此外掛最初將使用 get_template_part() 函數查找主題中的文件。如果您的主題中有一個名為 spot.php 的文件,則將其用於所有小工具的默認模板。 icit_spot() 函數可以使用第二個參數表示要使用的模板部分,例如:
<?php
if ( function_exists( 'icit_spot' ) )
icit_spot( 'Copyright', 'copyright' );
?>
上述代碼將使插件在主題文件夾中查找名為 spot-copyright.php 的文件,用於輸出。如果該文件不可用,它會退回到 spot.php,如果仍然不可用,它將簡單地輸出小工具內容。
當您想要顯示小工具中的特色圖像或需要某些其他/替代的標記時,請使用模板。小工具就像文章一樣,因此在模板中使用 the_content() 檢索小工具的內容,就像在循環中檢索一樣。
基本的小工具模板示例:
<div class="spot">
<?php the_content(); ?>
</div>
具有特色圖像的小工具模板:
<div class="spot-with-image">
<?php
if ( has_post_thumbnail() )
the_post_thumbnail( 'medium' );
the_content(); ?>
</div>
另外
許多過濾器和鉤子可用於從小工具中獲取更多內容,所以請到插件主頁或
外掛標籤
開發者團隊
📦 歷史版本下載
原文外掛簡介
Here at interconnect/it we have a policy of developing client sites with the premise of “content manage everything!” That means the little notices on sites, minor widgets and so on should not only be content managed, but they should be easy for both an end-user and a developer to work with.
To that end, we developed Spots. This creates a custom post type that allows you to create widgets using a visual editor, whilst also giving developers an easy hook for the creation of content managable elements within a theme.
The plugin now uses caching in order to help ensure that the load on a typical site is kept to a minimum. Performance is important!
The plugin is prepared for translation, if you’d like to drop us a line about your translation you can contact us through our website.
Developer Notes
Spots provides 2 template tags for developers to use shown below with their supported arguments.
icit_spot( $id_or_name, $template );
$id_or_name: Required. A numeric ID or the name of a spot as a string.
$template: Optional. A string used in a call to get_template_part()
This template tag always echos out the spot.
icit_get_spot( $id_or_name, $template, $echo );
Same as the above with an extra argument:
$echo: Optional. Defaults to false. A boolean to indicate whether to echo the spot content or just return it.
Basic Usage
You can use spots to replace boilerplate text in your themes. If you have areas in your themes where typically you would hard code the text you could use the following code:
The above code would output the contents of a spot titled ‘Copyright’. If the spot does not exist it will be created as a draft. Spots in draft mode are only visible to logged in users with editing capabilities.
Templates
The plugin will initially look for a file in your theme using the get_template_part() function. If you have a file called spot.php in your theme that will be the default template for all spots. The icit_spot() function can take a second parameter for the template part to use for example:
The above code will make the plugin look in your theme folder for a file called spot-copyright.php to use for the output. If not available it will fall back to spot.php and if that is not available it will simply output the spot contents.
Use templates when you want to display a featured image from a spot or if you require some additional/alternative markup for the spot. Spots are just like posts, so in the templates you retrieve the contents of the spot using the_content() just as would in the loop.
Basic spot template example:
Spot template with featured image:
Additional
There are many filters and hooks available to get even more out of spots so drop by the plugin homepage or use the forums if there is something you need to do with spots but aren’t sure how.
