WordPress.org

Ready to get started?Download WordPress

Forums

AM Events
[resolved] Easier examples of integration (21 posts)

  1. f0u
    Member
    Posted 1 year ago #

    Got really glad when i found this plugin, it seams like the perfect event listing plugin i looked for. But my knowledge is rather limited in this and i really tried to implement it in the theme i use, but coulden't figure it out. Tried as you described in Other Notes to integrate it by "Creating a WP_Query" but have no clue why it dosen't work when i try to paste the code in the theme files.

    Is it possible to maybe add an "integration for dummies guide" to the plugin?. :)

    http://wordpress.org/extend/plugins/am-events/

  2. f0u
    Member
    Posted 1 year ago #

    i'am trying to display events by putting the code in a diffrent template files like this.

    <?php $args = array(
            'post_type' => 'am_event',
            'post_status' => 'publish',
        );
    
    $the_query = new WP_Query($args); ?>

    But nothing seams to work, no matter how i try do do it. I'am using theme "Self - A Responsive vCard WordPress Theme" from themeforest.

  3. Atte Moisio
    Member
    Plugin Author

    Posted 1 year ago #

    The code you posted seems ok, but it only creates the query. To display the event posts, you need to use $the_query to loop through and display all of them.

    So you need to add something like this below:

    if ($the_query->have_posts()) {
    	while ($the_query->have_posts()) {
    		$the_query->the_post();
    
    		$postId = $post->ID;
    
    		// GET EVENT DATA 
    
    		$startDate = am_get_the_startdate('Y-m-d H:i:s');
    		$endDate = am_get_the_enddate('Y-m-d H:i:s');
    		$venues = am_get_the_venue( $postId );
    		$eventCategories = am_get_the_category( $postId );
    
    		// DISPLAY EVENT CONTENT
    
    		the_title();
    
    		echo '<p>' . $startDate . '</p>';
    		echo '<p>' . $endDate . '</p>';
    
    		// echo the first venue
    		echo '<p>' . $venues[0]->cat_name . '</p>';
    
    		// echo list of all event categories with template tag
    		am_the_event_category();
    
    		the_content();
    
    	}
    }

    You also need to make sure you put the code in the right template file, like a custom page template.

    Hope this helps. I'll probably write more examples or an easier tutorial later this week.

  4. Atte Moisio
    Member
    Plugin Author

    Posted 1 year ago #

    Notice also that I added template tags in version 1.3.0, which makes it easier to get and display event data (dates, venues and categories).

  5. Atte Moisio
    Member
    Plugin Author

    Posted 12 months ago #

    I should also add that what you probably need is a child theme with a custom page template. That would allow you to update your theme without losing any modifications.

    I've created a simple working child theme for Twenty Twelve, with three custom page templates that can be assigned to any page. You could modify them to suit your own theme. Download here.

  6. elyonline
    Member
    Posted 7 months ago #

    Hey there, I have just come across your wonderful event plugin. It is ideal for my running club's training events.

    I downloaded your demo files, but I have to confess to not being very good with code. Are you able to tell me where your demo code goes the the page template below please? I was looking at the page-event-blog file. Essentially, I just want a page to show all upcoming events.

    <?php
    /**
     * The template used for displaying page content in page.php
     *
     */
    ?>
    
    <!-- Titlebar
        ================================================== -->
        <section id="titlebar">
            <!-- Container -->
            <div class="container">
    
                <div class="eight columns">
    
                    <h2><?php the_title(); ?> <?php $subtitle = get_post_meta($post->ID, 'pp_subtitle', true); if($subtitle)  echo "<span>".$subtitle."</span>";?>
                        <?php edit_post_link( __( 'Edit', 'purepress' ), '<span class="edit-link">', '</span>' ); ?>
                    </h2>
                </div>
                <div class="eight columns">
                    <?php if(ot_get_option('pp_breadcrumbs') != 'no') echo dimox_breadcrumbs(); ?>
    
                </div>
    
            </div>
            <!-- Container / End -->
        </section>
    <!-- Content
        ================================================== -->
    
        <!-- Container -->
        <div  id="post-<?php the_ID(); ?>" <?php post_class('container'); ?> >
            <div class="twelve alt columns" >
                <?php the_content(); ?>
                <?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'purepress' ), 'after' => '</div>' ) ); ?>
                  <?php
                // If comments are open or we have at least one comment, load up the comment template
            if ( comments_open() || '0' != get_comments_number() ) {
            echo '<div class="page-comments">';
                comments_template( '', true );
            echo '</div>';
        } ?>
            </div>
              <?php  get_sidebar(); ?>
        </div>
        <!-- Page Content / End -->

    I appreciate any help.

    Thank you,
    Karl

  7. Atte Moisio
    Member
    Plugin Author

    Posted 7 months ago #

    Generally you would want to replace the page's content with the content generated by the wp_query or simply add the query after the content.

    In your example, you could add the wp_query right after <?php the_content() ?>. If you need to enable comments for the events, you should also move all the comments stuff inside the query.

    Keep in mind that the page-event-blog example contains a lot of features that you may not need, like thumbnail, comments or featured posts. The bare minimum you need to loop through and display all posts is this:

    <?php $args = array(
            'post_type' => 'am_event',
        );
    
    $the_query = new WP_Query($args); ?>
    
    if ($the_query->have_posts()) {
    	while ($the_query->have_posts()) {
    		$the_query->the_post();
    
    		the_title();
                    the_content();
    	}
    }
  8. elyonline
    Member
    Posted 7 months ago #

    Thank you Atte.

    I tried the code you posted, but it isn't working for me. Please see below my bare minimum code template.

    What actual code do I paste after my 'event code here' note?

    <?php
    /**
     * Template Name: Runner Events
     *
     * A custom page template without sidebar.
     *
     * The "Template Name:" bit above allows this to be selectable
     * from a dropdown menu on the edit page screen.
     *
     * @package WordPress
     * @subpackage purepress
     * @since purepress 1.0
     */
    
    $htype = ot_get_option('pp_header_menu');
    get_header($htype);
    
    wp_reset_query(); ?>
    
    <!-- Titlebar
        ================================================== -->
        <section id="titlebar">
            <!-- Container -->
            <div class="container">
    
            <div class="eight columns">
    
            <h2><?php the_title(); ?> <?php $subtitle = get_post_meta($post->ID, 'pp_subtitle', true); if($subtitle)  echo "<span>".$subtitle."</span>";?>
                <?php edit_post_link( __( 'Edit', 'purepress' ), '<span class="edit-link">', '</span>' ); ?>
                </h2>
                </div>
    
            <div class="eight columns">
                <?php if(ot_get_option('pp_breadcrumbs') != 'no') echo dimox_breadcrumbs(); ?>
                </div>
    
            	</div><!-- Container / End -->
        </section>
    
    <!-- Content
        ================================================== -->
        <?php $layout = ot_get_option('pp_blog_layout'); ?>
        <!-- Container -->
        <div class="container <?php if($layout == 'left-sidebar') { echo "page-left"; }?>">
        <div class="twelve <?php if($layout == 'left-sidebar') { echo "alt2"; } else { echo "alt"; } ?> columns">
    
    <!-- Event Code To Go Here
        ================================================== -->
    
    	</div>
    
    <!-- Sidebar
        ================================================== -->
    <?php get_sidebar(); ?>
    
    </div>
    <!-- Container / End -->
    <?php wp_reset_query();  get_footer(); ?>

    Thank you so much for any additional guidance :)

    Karl

  9. Atte Moisio
    Member
    Plugin Author

    Posted 7 months ago #

    The code in my previous post should work just fine and seems like you are putting it in the right place.

    Are you sure the custom page template is actually being used? Also make sure the plugin is enabled and that you have created one or more events that can be shown. Does the page show any errors or does it just create a page with no events?

  10. elyonline
    Member
    Posted 7 months ago #

    Managed it myself. Just needed belief :)

  11. elyonline
    Member
    Posted 7 months ago #

    Just realised. The list is showing later dates first, how do I show nearest dates first?

    <?php $args = array(
            'post_type' => 'am_event',
            'post_status' => 'publish',
        	);
    
    		$the_query = new WP_Query($args); 
    
            if ($the_query->have_posts()) {
    		while ($the_query->have_posts()) {
    		$the_query->the_post();
    
    		$postId = $post->ID;
    
    		// GET EVENT DATA 
    
    		$startDate = am_get_the_startdate('l j F');
    
    		// DISPLAY EVENT CONTENT
    
    		echo '<strong>' . $startDate . '</strong>';
    		the_title( '<h3 style="color:red;">', '</h3>' );
    		the_content();
    
    		}
    		}
    
    		?>

    Many thanls,
    Karl

  12. Atte Moisio
    Member
    Plugin Author

    Posted 7 months ago #

    Just replace

    $args = array(
            'post_type' => 'am_event',
            'post_status' => 'publish',
        	);

    with

    $args = array(
    	'post_type' => 'am_event',
    	'post_status' => 'publish',
    	'orderby' => 'meta_value',
    	'meta_key' => 'am_startdate',
    	'order' => 'ASC',
    	'meta_query' => array(
    		array(
    			'key' => 'am_enddate',
    			'value' => date('Y-m-d H:i:s', time()),
    			'compare' => ">",
    		),
    	),
    );

    This will show only ongoing and upcoming events ordered by date from newest to latest

  13. elyonline
    Member
    Posted 7 months ago #

    Thanks for that Atte,

    I tried the code but there appears to be something missing as the code doesn't work.

    I really appreciate the support you have given :)

  14. Atte Moisio
    Member
    Plugin Author

    Posted 7 months ago #

    Hmm, it should be working, as I copied it straight from the page-event-blog example, which I have tested.

    Could you provide any additional information on how it doesn't work? What version of wordpress and php are you using?

  15. elyonline
    Member
    Posted 7 months ago #

    My bad. Realised I didn't put the PHP start tag at the beginning.

    For some reason though I am only getting 2 results. For instance it is omitting today's events. How do I show them?

  16. Atte Moisio
    Member
    Plugin Author

    Posted 7 months ago #

    It should show all events which haven't ended yet.

    You can fiddle with the time() function to change how long ago the events are shown. You could for example replace time() with time() - (24 * 60 * 60) to show events with an end time greater than 24h before the current time.

  17. elyonline
    Member
    Posted 7 months ago #

    Thanks for the heads up. The widget shows today's events though.

    Will play around with time. Thank you

  18. elyonline
    Member
    Posted 6 months ago #

    Hi there,

    I would like to use what is generated in the sidebar of AM Events into my main frontpage that doesn't warrant a sidebar.

    Is there a way to do this please?

    Thanks

  19. Atte Moisio
    Member
    Plugin Author

    Posted 6 months ago #

    Hi,

    Unfortunately the shortcode/templating system is only for the widget at the moment, as the events are otherwise intended to be showed using custom templates and wp_query.

    However, you could try finding a plugin that allows inserting widgets into pages.

  20. emtuzas
    Member
    Posted 5 months ago #

    Can you help me also please, I'm having issue on creating a page that will list all events posted for all cats/venues.

    I created a page called EVENTS and set the template that i called "Cycling Events" the template file I also created in theme directory events-template.php, below i'm posting what I have in that events-template.php file -

    <?php
    /**
     * Template Name: Cycling Events
     *
     */
    get_header(); ?>
    
    <!-- Event Code To Go Here
        ================================================== -->
    
    <?php $args = array(
            'post_type' => 'am_event',
            'post_status' => 'published',
        );
    
    $the_query = new WP_Query($args);
    
    if ($the_query->have_posts()) {
    	while ($the_query->have_posts()) {
    		$the_query->the_post();
    
    		$postId = $post->ID;
    
    		// GET EVENT DATA 
    
    		$startDate = am_get_the_startdate('Y-m-d H:i:s');
    		$endDate = am_get_the_enddate('Y-m-d H:i:s');
    		$venues = am_get_the_venue( $postId );
    		$eventCategories = am_get_the_category( $postId );
    
    		// DISPLAY EVENT CONTENT
    
    		the_title();
    
    		echo '<p>' . $startDate . '</p>';
    		echo '<p>' . $endDate . '</p>';
    
    		// echo the first venue
    		echo '<p>' . $venues[0]->cat_name . '</p>';
    
    		// echo list of all event categories with template tag
    		am_the_event_category();
    
    		the_content();
    
    	}
    }
    ?>
    
    <!-- Sidebar
        ================================================== -->
    <?php get_sidebar('home'); ?>
    
    <!-- Container / End -->
    
    <?php get_footer(); ?>

    Thank you!

  21. emtuzas
    Member
    Posted 5 months ago #

    Looks like i figured out the problem... However, what i really need
    is to list it like on your examples.php in table format and so on.
    If I just take examples.php and paste the code into my template, it doesnt work...

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic