dongzhuo5425 2015-03-04 16:13
浏览 26
已采纳

Wordpress插件活动日历 - 列出一年的所有活动

I've been struggling (I'm a newb) on how to have The Events Calendar print a list of all events within a specified year. I researched this need heavily online and I'm surprised that there's limited info on the subject. The list is simple really. It just needs to be a linked title that sends the user to the actual event page.

My approach was to create a custom [shortcode] in functions.php so I could place the list on any WordPress page or post that I need.

The custom shortcode PHP is the following.

add_shortcode('yearList', 'yearList');
function sayHello()
{
echo '<h1>Hello World</h1>';
}

I added this to the functions.php file within the Genesis child theme root. The text echoed fine so that part is good to go.

After researching the forums at Modern Tribe I came across a useful page that reviews the tribe_get_events function. Here's the page for those wondering.

Any way, the code in this page gets me close so I know I'm on the right track. The PHP that I'm using within the created shortcode function is the following.

// 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.

}
}

I have two questions.

  1. Why would the loop only show nine titles when I have over 80 stamped for 2014?
  2. How can make each line be a link to The Calendar Events actual event page? I've tried to employ this with no luck.

Thanks for any help on this.

  • 写回答

1条回答 默认 最新

  • douzhong8856 2015-03-04 16:27
    关注

    For your first problem, try adding posts_per_page => -1 inside your $events = tribe_get_events( array( ... ); statement. The default limit must be set to 9 posts somewhere. If that doesn't work, try replacing -1 with a large number.

    For the output issue, you can't echo an echo in php. Try this instead:

    $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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)