-
16-10-2019 - |
题
我想在WordPress 3.0网站上添加一个新区域 每天包含来自YouTube的新视频. 。该视频将被手动挑选,并每天手动添加。我不确定如何正确设置这个问题。
我目前的思想过程是我将创建一个称为“视频,“然后每天在该类别中添加一个新帖子,将嵌入式代码放在后体内。虽然这看起来像是丑陋的黑客,所以我可以接受一个更好,更瘦的解决方案。理想情况下,我会拥有一个简单的管理员 - 我将在标题中放置的范围以及指向YouTube视频的链接(以编程方式将链接转换为我自己的嵌入代码)。
WordPress 3.0是否会很好地适应这样的奇数帖子类型?我应该阅读什么,以更好地了解我将如何完成类似的事情 “一天的视频”, , 和 “每日卡通”?
解决方案
我建议使用 自定义帖子类型 处理这个。您可以添加自定义帖子类型并将其设置为仅接受YouTube URL作为内容。然后,您可以在主页上使用自定义循环显示此设置中的“最新”帖子。
首先,这里还有其他几个好的资源:
其他提示
你好 @Jonathan Sampson:
@eamann是现场,自定义帖子类型是必经之路。
这是您可以在主题中扔的代码 functions.php
文件以实现您需要的自定义帖子类型(请注意,我包含了助手功能 make_post_type_labels()
我喜欢使用可以降低定义自定义帖子类型的复杂性):
register_post_type('daily-video',
array(
'labels' => make_post_type_labels('Daily Video'),
'public' => true,
'show_ui' => true,
'query_var' => 'daily-video',
'rewrite' => array('slug' => 'daily-videos'),
'hierarchical' => true,
'supports' => array('title','editor',
)
);
function make_post_type_labels($singular,$plural=false,$args=array()) {
if ($plural===false)
$plural = $singular . 's';
elseif ($plural===true)
$plural = $singular;
$defaults = array(
'name' =>_x($plural,'post type general name'),
'singular_name' =>_x($singular,'post type singular name'),
'add_new' =>_x('Add New',$singular),
'add_new_item' =>__("Add New $singular"),
'edit_item' =>__("Edit $singular"),
'new_item' =>__("New $singular"),
'view_item' =>__("View $singular"),
'search_items' =>__("Search $plural"),
'not_found' =>__("No $plural Found"),
'not_found_in_trash' =>__("No $plural Found in Trash"),
'parent_item_colon' =>'',
);
return wp_parse_args($args,$defaults);
}
另外,您可能会发现这两个答案也很有帮助: