所以我遇到了在我的 Artisteer 主题中没有任何帖子元数据(发布日期、类别等)的问题。我在艺术家设计程序中禁用了它们,因为我不希望我的整个页面看起来像一个博客,而是一个专业页面。
然而,后来我意识到我确实想要我的新闻部分(实际上只是一个博客页面)的发布日期、帖子类别等数据。
我该如何取回它?
事实证明这比你想象的要难一些......在早期版本的 WP 和 Artisteer 中,你可以找到处理输出的文件,即索引、页面等,但现在它们都包含在相互调用的函数中=)
它是这样的: WP 中的每个页面都有一个模板文件(可以在创建页面时指定),请阅读 WP Codex 中有关页面模板的更多信息。您的博客页面从 home.php 或 archive.php 运行(取决于您是查看帖子存档还是只是常规的“主页”项目,我称我的“新闻”为“新闻”,因为博客只是一个小新闻我网站的部分)。
打印出帖子的循环如下所示:
/* Start the Loop */
while (have_posts()) {
the_post();
get_template_part('content', '');
}
因此,在此页面模板文件中控制的所有内容与帖子输出有关的是使用哪个内容过滤器模板。在您的 Artisteer 3.1 主题中,您将有许多 content.php 文件,上面的函数将调用 content.php 但您可以为您的页面设置一个 content-page.php 等。让我们看看我的 content.php 然后...
global $post;
theme_post_wrapper(
array(
'id' => theme_get_post_id(),
'class' => theme_get_post_class(),
'thumbnail' => theme_get_post_thumbnail(),
'title' => theme_get_meta_option($post->ID, 'theme_show_page_title') ? get_the_title() : '',
'heading' => theme_get_option('theme_'.(is_single()?'single':'posts').'_article_title_tag'),
'before' => theme_get_metadata_icons('date,category', 'header' ),
'content' => theme_get_excerpt(),
'after' => theme_get_metadata_icons( '', 'footer' )
)
);
所以这个文件真正做的就是确定哪些部分的数据要包含在这个模板中。当我在这里深入研究时,我开始感到恼火......打印我的 html 元素的实际代码在哪里?我可以从哪里开始“破解”我的主题?如您所见,上面的“之前”行包含项目“数据、类别”和样式的附加值“标题”。所以让我们看看我们的主题functions.php中的那个函数......
function theme_get_metadata_icons($icons = '', $class=''){
global $post;
if (!is_string($icons) || theme_strlen($icons) == 0) return;
$icons = explode(",", str_replace(' ', '', $icons));
if (!is_array($icons) || count($icons) == 0) return;
$result = array();
for($i = 0; $i < count($icons); $i++){
$icon = $icons[$i];
switch($icon){
case 'date':
$result[] = '<span class="art-postdateicon">' . sprintf( __('<span class="%1$s">Published</span> %2$s', THEME_NS),
'date',
sprintf( '<span class="entry-date" title="%1$s">%2$s</span>',
esc_attr( get_the_time() ),
get_the_date()
)
) . '</span>';
break;
case 'category':
$categories = get_the_category_list(', ');
if(theme_strlen($categories) == 0) break;
$result[] = '<span class="art-postcategoryicon">' . sprintf(__('<span class="%1$s">Posted in</span> %2$s', THEME_NS), 'categories', get_the_category_list(', ')) . '</span>';
break;
//other options such as author etc. are included here by default, I took them out for the sake of this example...
}
}
$result = implode(theme_get_option('theme_metadata_separator'), $result);
if (theme_is_empty_html($result)) return;
return "<div class=\"art-post{$class}icons art-metadata-icons\">{$result}</div>";
}
所以该函数只提取一些数据,并将其包装在一些主题样式中,但我仍然没有找到可以注释掉包含“发布者”等信息的实际 html 元素的地方。记住我丢失了日期戳,所以我认为它在某处被注释掉了。
最后要看的地方是函数theme_post_wrapper(),如果你退一步,你会看到theme_post_wrapper()是这个函数,它反过来调用上面的函数,提取数据并将其包装在一些样式元素中. 你会认为这个函数会在functions.php中的某个地方,对吧?但是没有...函数 theme_post_wrapper( 的目录搜索显示它在主题文件 library/wrappers.php 中。它看起来像这样:
function theme_post_wrapper($args = '') {
$args = wp_parse_args($args,
array(
'id' => '',
'class' => '',
'title' => '',
'heading' => 'h2',
'thumbnail' => '',
'before' => '',
'content' => '',
'after' => ''
)
);
/*
var_dump($args);
die;
*/
extract($args);
if (theme_is_empty_html($title) && theme_is_empty_html($content)) return;
if ($id) {
$id = ' id="' . $id . '"';
}
if ($class) {
$class = ' ' . $class;
}
?>
<div class="art-box art-post<?php echo $class; ?>"<?php echo $id; ?>>
<div class="art-box-body art-post-body">
<div class="art-post-inner art-article">
<?php
if (!theme_is_empty_html($title)){
echo '<'.$heading.' class="art-postheader">'$before.': '.$title.' <span class="published_date">('.$after.')</span></'.$heading.'>';
//original: echo '<'.$heading.' class="art-postheader">'.$title.'</'.$heading.'>';
}
echo $thumbnail;
?>
<div class="art-postcontent">
<!-- article-content -->
<?php echo $content; ?>
<!-- /article-content -->
</div>
<div class="cleared"></div>
<?php
?>
</div>
<div class="cleared"></div>
</div>
</div>
这是我的元数据元素最终打印出来的地方,现在我有宾至如归的感觉,世界又一切正常了。我再一次感谢 Artisteer,虽然它有点混乱,而且很费时间来了解这个的具体细节。
请注意我的问题的解决方案:Artisteer 的工作方式如下:当您选择不在主题中包含日期或作者元数据时,artisteer 不仅关闭选项或注释掉打印这些元素的代码,它实际上根本不会生成该代码。所以我不得不手动把它放回那里。很公平 - 我想艺术家主题不是为了以这种方式被黑客攻击和调整的,但我仍然比那些 21 和 211 主题的逻辑更喜欢它们=p