我在自定义帖子类型中遇到问题我写了wordpress自定义帖子类型的代码一切正常,但我想让全局代码到处调用。但是,当我尝试制作2个不同的文件以使代码全局化然后显示错误" 500错误"
这是代码
protocol GroupDelegate {
func groupDidSelectRow(selectedRow: Int)
}
class GroupTableView: NSTableView, NSTableViewDelegate, NSTableViewDataSource, NSMenuDelegate {
var groupDelegate:GroupDelegate?
override func draw(_ dirtyRect: NSRect) {
super.draw(dirtyRect)
self.delegate = self
self.dataSource = self
self.groupDelegate = TemplateTableView()
}
func tableViewSelectionDidChange(_ notification: Notification) {
groupDelegate?.groupDidSelectRow(selectedRow: self.selectedRow)
}
}
class TemplateTableView: NSTableView, NSTableViewDelegate, NSTableViewDataSource, GroupDelegate {
var groupSelectedRow = 0
override func draw(_ dirtyRect: NSRect) {
super.draw(dirtyRect)
self.delegate = self
self.dataSource = self
}
func groupDidSelectRow(selectedRow: Int) {
groupSelectedRow = selectedRow
reloadData() // This line is not working
}
}
和其他全局文件名中的其他代码是templates-sections / Portfol.php
$custom_terms = get_field('portfolio_gallery_category_name');
print_r(get_field('portfolio_gallery_category_name'));
foreach($custom_terms as $custom_term):
wp_reset_query();
$args = array('post_type' => 'portfolio',
'tax_query' => array(
array(
'taxonomy' => 'portfolio_type',
'field' => 'term_id',
'terms' => $custom_term->term_id,
),
),
);
$loop = new WP_Query($args);
include('templates-sections/portfolios.php');
我报告了所有错误但同样的事情显示" 500"任何人都可以帮助解决此问题。
我知道很多人都有解决方案,有人解决这个小问题。
提前致谢。
答案 0 :(得分:0)
您可以在第二个文件中创建一个函数,并在第一个文件中调用它。
<?php
$custom_terms = get_field('portfolio_gallery_category_name');
print_r(get_field('portfolio_gallery_category_name'));
include('templates-sections/portfolios.php');
foreach($custom_terms as $custom_term):
wp_reset_query();
$args = array('post_type' => 'portfolio',
'tax_query' => array(
array(
'taxonomy' => 'portfolio_type',
'field' => 'term_id',
'terms' => $custom_term->term_id,
),
),
);
$loop = new WP_Query($args);
myFunction( $loop );
endforeach;
?>
你的第二个档案
<?php
error_reporting(E_ALL);
function myFunction( $loop ) {
if($loop->have_posts()):
while($loop->have_posts()) : $loop->the_post();
?>
<div class="col-lg-3 col-md-4 col-sm-6 p-0 scale-anm" data-aos="fade-zoom">
<a href="<?php the_post_thumbnail_url('full'); ?>" data-toggle="lightbox" data-gallery="example-gallery">
<img src="<?php the_post_thumbnail_url('full'); ?>" class="img-responsive" /></a>
</div>
<?php endwhile;
endif;
}
?>