Php Wordpress插件事件日历-列出一年的所有事件
我一直在努力(我是一个新手)如何让活动日历打印指定年份内所有活动的列表。我在网上对这一需求进行了大量的研究,我很惊讶关于这一主题的信息有限。清单很简单。它只需要是一个链接的标题,将用户发送到实际的事件页面 我的方法是在functions.php中创建一个自定义的[shortcode],这样我就可以将列表放在我需要的任何WordPress页面或帖子上 自定义短代码PHP如下所示Php Wordpress插件事件日历-列出一年的所有事件,php,wordpress,list,plugins,Php,Wordpress,List,Plugins,我一直在努力(我是一个新手)如何让活动日历打印指定年份内所有活动的列表。我在网上对这一需求进行了大量的研究,我很惊讶关于这一主题的信息有限。清单很简单。它只需要是一个链接的标题,将用户发送到实际的事件页面 我的方法是在functions.php中创建一个自定义的[shortcode],这样我就可以将列表放在我需要的任何WordPress页面或帖子上 自定义短代码PHP如下所示 add_shortcode('yearList', 'yearList'); function sayHello() {
add_shortcode('yearList', 'yearList');
function sayHello()
{
echo '<h1>Hello World</h1>';
}
add_shortcode('yearList','yearList');
函数sayHello()
{
回声“你好世界”;
}
我将其添加到Genesis子主题根目录中的functions.php文件中。这篇课文的回音很好,所以这一部分很好
在研究了Modern Tribe的论坛后,我发现了一个有用的页面,其中回顾了Tribe_get_events函数
不管怎样,这一页中的代码让我很接近,所以我知道我在正确的轨道上。
我在创建的shortcode函数中使用的PHP如下所示
// Setting up custom function called yearList
add_shortcode('yearList', 'yearList');
function yearList()
{
// Ensure the global $post variable is in scope
global $post;
// Retrieve all events desired year. Only eight printed out of 80.
$events = tribe_get_events( array(
'eventDisplay' => 'custom',
'start_date' => '2014-01-01 00:01',
'end_date' => '2014-12-31 23:59'
) );
// Loop through the events: set up each one as
// the current post then use template tags to
// display the title and content
foreach ( $events as $post ) {
setup_postdata( $post );
// prints the title for each event.
echo '<br><br>';
// WRONG WRONG - This is below is what's throwing me.
echo '<a href="<?php echo tribe_get_event_link() ?>" title="<?php the_title() ?>"></a>';
//the_title();
// echo tribe_get_start_date(); This shows the start date and time after the event title I slept this for now.
}
}
//设置名为yearList的自定义函数
添加_短代码(“年表”、“年表”);
功能年表()
{
//确保全局$post变量在范围内
全球$员额;
//检索所需年份的所有事件。80个事件中仅打印8个。
$events=tribe\u get\u事件(数组(
'事件显示'=>'自定义',
“开始日期”=>“2014-01-01 00:01”,
“结束日期”=>“2014-12-31 23:59”
) );
//循环浏览事件:将每个事件设置为
//然后,当前帖子将使用模板标记
//显示标题和内容
foreach($events as$post){
设置_postdata($post);
//打印每个事件的标题。
回音“
”;
//错-这是下面是什么扔我。
回声';
//_title();
//echo tribe_get_start_date();这显示了事件标题之后的开始日期和时间。
}
}
我有两个问题。
感谢您在这方面的帮助。对于您的第一个问题,请尝试在
$events=tribe\u get\u events(array(…);
语句中添加posts\u per\u page=>-1
。默认限制必须在某个位置设置为9篇文章。如果不起作用,请尝试用大数字替换-1
对于输出问题,您不能在php中使用echo
anecho
。请尝试以下方法:
$ev_link = tribe_get_event_link();
$ev_title = get_the_title();
printf('<a href="%1$s" title="%2$s">%2$s</a>', $ev_link, $ev_title);
$ev_link=tribe_get_event_link();
$ev_title=获取_title();
printf(“”,$ev_link,$ev_title);
是的!谢谢cpiko。成功了。非常感谢!