我正在寻求帮助解决我遇到的一个问题,而我似乎无法锻炼自己。我已经创建了自己的自定义分类法,称为系列(代码如下)。我在一个小部件中使用一个名为;“灵活发布”小部件;(下面小部件的屏幕截图和下面插件的代码)。
这很好,它调用了posts。但我想创建一个;查看全部“;指向任何内容的链接;“系列”;(我的自定义分类法)在小部件中调用。我尝试了permalink,但它转到了被调用的最后一篇文章,而不是列出该小部件中当前正在调用的分类法下的所有文章的页面。我正在寻找一种链接到该页面的方法,并将其动态化为自定义分类法;“系列”;将根据小部件中调用的序列而更改。
非常感谢您的指导-我将非常积极响应!
functions.php / Where I register the taxonomy
function create_series_hierarchical_taxonomy() {
$labels = array(
\'name\' => _x( \'series\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'series\', \'taxonomy singular name\' ),
\'search_items\' => __( \'search series\' ),
\'all_items\' => __( \'all series\' ),
\'parent_item\' => __( \'parent series\' ),
\'parent_item_colon\' => __( \'parent series:\' ),
\'edit_item\' => __( \'edit series\' ),
\'update_item\' => __( \'update series\' ),
\'add_new_item\' => __( \'add new series\' ),
\'new_item_name\' => __( \'new series name\' ),
\'menu_name\' => __( \'series\' ),
);
$args = array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'series\' ),
\'show_in_rest\' => true,
);
register_taxonomy(\'series\', array(\'post\'), $args );
}
The Flexible Posts Widget Code Template I edited to call my posts
// Block direct requests
if ( !defined(\'ABSPATH\') )
die(\'-1\');
echo $before_widget;
if ( !empty($title) )
echo $before_title . $title . $after_title;
if( $flexible_posts->have_posts() ):
?>
<div>
<?php
// This sets out a variable called $term - we\'ll use it ALOT for what we\'re about to do.
$term = get_term_by( \'slug\', get_query_var( \'term\' ), get_query_var( \'taxonomy\' ) ); ?>
<?php while( $flexible_posts->have_posts() ) : $flexible_posts->the_post(); global $post; ?>
<h2><?php echo $term->name; ?></h2><!-- Prints the term name as set in the Widget -->
<a href="<?php the_permalink(); ?>"><p><?php the_title();?></p></a>
<?php endwhile; ?>
</div>
<a href="<?php the_permalink(); ?>">View All</a> <!-- This doesn\'t link to the current "Series" taxonomy page like I want it to -->
<?php else: // No Posts ?>
<div class="dpe-flexible-posts no-posts">
<p><?php _e( \'Empty\', \'flexible-posts-widget\' ); ?></p>
</div>
<?php
endif; // End have_posts()
echo $after_widget;
Widget Screenshot For Visual Reference If It Helps
UPDATE
@bdtheme提供的答案返回此错误消息,仍在寻找解决方案:
(!)可捕获的致命错误:类WP\\u error的对象无法转换为字符串inC:。。\\wordpress\\wp content\\plugins\\flexible posts widget\\views\\series模板。phpon 46号线
调用堆栈#TimeMemoryFunctionLocation 10.0005240784{main}()。。。\\索引。php:0 20.0008243888require(\'C:..\\wordpress\\wp blog header.php\')。。。\\索引。菲律宾比索:17
30.717639617200require\\u一次(\'C:..\\wordpress\\wp includes\\template loader.php\')。。。\\wp博客标题。php:19 40.721039663800包括(\'C:..\\wordpress\\wp content\\themes\\hf\\front page.php\')。。。\\模板加载器。php:74 50.892539948680dynamic\\u提要栏()。。。\\首页。php:95 60.894139952688call\\u user\\u func\\u数组:{C:..\\wordpress\\wp includes\\widgets。php:743}()。。。\\小部件。php:743 70.894139953272WP\\U小部件->;display\\u callback()。。。\\小部件。php:743 80.894339963256Flexible\\u Posts\\u Widget->;widget()。。。\\类wp小部件。php:372 90.9027400010816包括(\'C:..\\wordpress\\wp content\\plugins\\flexible posts widget\\views\\series template.php\')。。。\\类fpw小部件。菲律宾比索:197