php 存档模板与自定义Beaver Builder发布模块

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 存档模板与自定义Beaver Builder发布模块相关的知识,希望对你有一定的参考价值。

<?php
/**
 * Customized archive template
 * Intended to be used in a child theme as index.php
 * Outputs a Beaver Builder posts module for archive pages
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package pixablaze_base
 */

/********** Configuration ************
 * Purpose: set archive page to use a saved Beaver Builder template
 * Create a saved BB template using a standard Posts module (change ID below)
 * In the BB posts module, use default query settings (this should override it)
 ************************************/
$bb_archive_id = 28; // edit to match the ID of the saved template or row 

/************ Filter posts **********
 * Filter the Beaver Builder $query for the posts module on archive pages
 * Note: this filter is here for a convenient view of related functions. 
 * this would typically be in functions.php or a custom plugin.
 ************************************/

add_filter( 'fl_builder_loop_query', 'pxb_bb_category_archives', 10, 2 );
function pxb_bb_category_archives( $query, $settings ) 
{
	// if not on a category or tag page, return the default query
	if( ! is_category() && ! is_tag() ) return $query;
	
	// get all the query args so we can return the whole object
	$query_args = $query->query_vars;

	// set the category and tag ids and names from the current post
	// this filters the BB posts module settings depending on which archive is being viewed
	$query_args[ 'cat' ] = get_query_var( 'cat' );
	$query_args[ 'category_name' ] = get_query_var( 'category_name' );
	$query_args[ 'tag' ] = get_query_var( 'tag' );
	$query_args[ 'tag_id' ] = get_query_var( 'tag_id' );

	// return the filtered query
	return new WP_Query( $query_args );
}

/************************************
 * Start the template
 ***********************************/
get_header(); ?>

	<div id="primary" class="content-area">
		<main id="main" class="site-main" role="main">

			<?php 
			// Check if Builder is activated and the supplied post ID exists
			$test_post = get_post( $bb_archive_id );
			if ( !class_exists( 'FLBuilderModel' ) || !is_object( $test_post ) ) {
				// something is wrong, use default loop
				get_template_part( 'template-parts/content', get_post_format() );
			} else {
				// Post exists and Builder is active - output the BB layout
				echo do_shortcode( '[fl_builder_insert_layout id="'. $bb_archive_id. '"]' );
			} ?>

		</main><!-- #main -->
	</div><!-- #primary -->

<?php get_footer(); ?>

以上是关于php 存档模板与自定义Beaver Builder发布模块的主要内容,如果未能解决你的问题,请参考以下文章

更改 slug 时存档-post_type.php 中断

php 向Beaver Themer添加其他自定义字段

joomla T3框架中模板分离与自定义(local文件夹 实战研究)

php 在Beaver Themer中的作者档案中选择当前作者的帖子模块(自定义查询)

使用存档页面中的 ACF 字段进行自定义帖子

使引导弹出框与自定义 html 模板一起使用