Php 主题元数据(日期、类别)丢失
我为wordpress和artisteer发疯了。我正在尝试一些过去非常简单的事情——在我的博客页面上打开和关闭我的文章的日期和文章类别的显示 我在content.php中找到了这一点Php 主题元数据(日期、类别)丢失,php,wordpress,Php,Wordpress,我为wordpress和artisteer发疯了。我正在尝试一些过去非常简单的事情——在我的博客页面上打开和关闭我的文章的日期和文章类别的显示 我在content.php中找到了这一点 global $post; theme_post_wrapper( array( 'id' => theme_get_post_id(), 'class' => theme_get_post_class(), 'title' => the
global $post;
theme_post_wrapper(
array(
'id' => theme_get_post_id(),
'class' => theme_get_post_class(),
'title' => theme_get_meta_option($post->ID, 'theme_show_page_title') ? get_the_title() : '',
'heading' => theme_get_option('theme_single_article_title_tag'),
'before' => theme_get_metadata_icons('date', 'header'),
'content' => theme_get_content()
)
);
说明上说,你所要做的就是在“之前”行中插入或删除“日期”。我已经用我的内容文件来回地做了,输出没有任何变化
我找不到打印所有内容的实际代码,wordpress在所有内容被深入挖掘10层之前都非常简单,现在你必须查看数百万个不同的函数才能找到最简单的东西
正如您可能知道的,我通常不使用WP=)但这是我现在的工作表,我已经有几年没有更新WP了
任何关于我在哪里可以找到变量的输入都是非常感谢的
我本来希望在某个时候能找到
“发布于”.echo($date)。”在类别中.echo($category)
或者至少有点类似的东西…所以我遇到了一个问题,在我的主题中没有任何帖子元数据(发布日期、类别等)。我在artisteer设计项目中禁用了它们,因为我不希望我的整个页面看起来像一个博客,而是一个专业页面 然而,后来我意识到,我确实希望我的新闻部分(实际上只是一个博客页面)有发布日期、文章类别等数据 我怎么把它拿回来 事实证明这比你想象的要难一些。。。在WP和artisteer的早期版本中,您可以只找到处理输出的文件,即索引、页面等,但现在它都包含在相互调用的函数中=) 事情是这样的: WP中的每个页面都有一个模板文件(可以在创建页面时指定),请阅读WP Codex中有关页面模板的更多信息。 你的博客页面运行在home.php或archive.php之外(取决于你是否正在查看文章的存档或只是常规的“主页”项目,我称我的博客为“新闻”,因为博客只是我网站的一个小新闻部分) 打印帖子的循环如下所示:
/* Start the Loop */
while (have_posts()) {
the_post();
get_template_part('content', '');
}
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>
所以,在这个页面模板文件中,关于post输出的所有控制就是使用哪个内容过滤器模板。在您的Advistor 3.1主题中,您将拥有许多内容.PHP文件,上面的函数将调用Cordon .PHP,但是您可以有一个页面Pr.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元素的实际代码在哪里?我从哪里开始“破解”我的主题?如您所见,上面“before”的行包含“data,category”项和样式“header”的附加值。让我们看看themes 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>";
}
函数主题\u获取\u元数据\u图标($icons='',$class=''){
全球$员额;
如果(!is_string($icons)| theme_strlen($icons)==0)返回;
$icons=explode(“,”,str_replace(“,”,$icons));
如果(!is_array($icons)| count($icons)==0)返回;
$result=array();
对于($i=0;$i
因此,该函数只提取一些数据,并将其包装在一些主题样式中,但我仍然没有找到可以注释掉包含“posted by”等信息的实际html元素的位置。
记得我把日期戳弄丢了,所以我以为它被注释掉了
最后一个要查看的地方是函数theme_post_wrapper(),如果您后退一步,您将看到theme_post_wrapper()是一个函数,它依次调用上述函数,该函数提取数据并将其包装在一些样式元素中。您会认为这个函数应该在functions.php中的某个地方,对吗?但是没有。。。对函数theme_post_wrapper的目录搜索(显示它位于主题文件library/wrappers.php中,如下所示:
/* Start the Loop */
while (have_posts()) {
the_post();
get_template_part('content', '');
}
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>
function-theme\u-post\u包装($args=''){
$args=wp\u parse\u args($args,
排列(
“id'=>”,
“类”=>“”,
'标题'=>'',
“标题”=>“h2”,
'缩略图'=>'',
'在'=>''之前,
'内容'=>'',
'在'=>''之后'
)
);
/*
var_dump($args);
死亡
*/
摘录($args);
if(theme_是空的html($title)&&theme_是空的html($content))返回;
如果($id){
$id='id=“”.$id.'”;
}
如果($类){
$class=''.$class;
}
?>