【发布时间】:2016-02-23 12:34:54
【问题描述】:
对于我正在开发的一个 wordpress 自定义主题,
我必须做什么才能获得:
<a class="archive_link" href...> 而不是:<a href...>
从 wp_get_archives 函数获取一个小部件?
在functions.php中我有这个:
function sxo_widgets_init() {
register_sidebar( array(
'name' => __( 'Primary Widget Area', 'sxo' ),
'id' => 'sidebar-1',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>'
) );
}
add_action( 'widgets_init', 'sxo_widgets_init' );
在side.php 模板中我有:
...
<ul>
<?php wp_get_archives( array( 'type' => 'monthly') ); ?>
</ul>
...
(已更新)而且,我忘了在 funtions.php 中说:
function sxo_widgets_init() {
register_sidebar( array(
'name' => __( 'Primary Widget Area', 'sxo' ),
'id' => 'sidebar-1',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>'
) );
}
add_action( 'widgets_init', 'sxo_widgets_init' );
(更新 2-aside.php:)
<?php
/**
* The Sidebar containing the main widget areas.
*
* @package sxo
* @since sxo 1.0
*/
?>
<div id="secondary" class="widget-area" role="complementary">
<?php do_action( 'before_sidebar' ); ?>
<?php if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>
<aside id="search" class="widget widget_search">
<?php get_search_form(); ?>
</aside>
<aside id="archives" class="widget">
<h1 class="widget-title"><?php _e( 'Archives', 'sxo' ); ?></h1>
<ul class="archive-sidebar">
<?php wp_get_archives( array( 'type' => 'monthly') ); ?> <!--'before' => '<a class="widget-link">', 'after' => '</a>'?>-->
<?php /*wp_get_archives( array( 'type' => 'monthly', 'format' => 'custom', 'before' => '<a class="widget-link">', 'after' => '</a>') ); ?> <!--'before' => '<a class="widget-link">', 'after' => '</a>'?>-->
<?php //<?php wp_get_archives( 'format=custom&before=<p id="test">&after=</p>&type=postbypost&limit=100' );
/*Step #3
Now instead of a unordered list using <li></li>, the code will now be <p></p> and you are ready to go to town on customizations. Endless possibilities.*/?>
</ul>
</aside>
<aside id="meta" class="widget">
<h1 class="widget-title"><?php _e( 'Meta', 'sxo' ); ?></h1>
<ul>
<?php wp_register(); ?>
<li><?php wp_loginout(); ?></li>
<?php wp_meta(); ?>
</ul>
</aside>
<?php endif; // end sidebar widget area ?>
</div><!-- #secondary .widget-area -->
<?php if ( is_active_sidebar( 'sidebar-2' ) ) : ?>
<div id="tertiary" class="widget-area" role="supplementary">
<?php dynamic_sidebar( 'sidebar-2' ); ?>
</div><!-- #tertiary .widget-area -->
<?php endif; ?>
(更新 3)- 哪里(从我的 front-page.php 模板中提取的代码)我正在尝试包含 aside.php:
<?php
/*
Template Name: Front-page - Portada de sxo
@package WordPress
* @subpackage sxo
*/
get_header('front-page'); ?>
<div id="contenido" class="wrapper clearfix">
<section id="list_posts_home">
<div id="content" class="widecolumn">
<?php if (have_posts()) : while (have_posts()) : the_post();?>
<div class="listed_post_home">
<h2 id="post-<?php the_ID(); ?>"><a class="linkHomeBlog" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
<div class="entrytext">
<div style="float:left;margin-right:1.5em;"><?php the_post_thumbnail(); ?></div>
<p><?php
the_excerpt('<a href="<?php the_permalink(); ?>">Read more</a></p>');?>
<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
</div>
</div>
<?php endwhile;
sxo_content_nav( 'nav-below' );
endif; ?>
</div>
<?php get_sidebar(); ?>
</section>
(更新 4)sidebar.php 模板:
<?php
/**
* The sidebar containing the main widget area.
*
* If no active widgets in sidebar, let's hide it completely.
*
* @package WordPress
* @subpackage sxo
* @since sxo
*/
?>
<?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
<div id="secondary" class="widget-area" role="complementary">
<?php dynamic_sidebar( 'sidebar-1' ); ?>
</div><!-- #secondary -->
<?php endif; ?>
提前致谢!
【问题讨论】:
标签: php css wordpress class widget