Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #2966
    Word P
    Participant

    Hello,

    Thanks for the great plugin!
    I do have a little problem.
    I installed it and made a template of the news page so I could alter a few things.
    In the template I added the widget calendar and everything works fine when I select
    a certain date on the calendar as long as I don’t go to another month.
    The moment that I go to another month and
    I try to select a certain date, it goes to this page: wp-admin/admin-ajax.php?news_ondate=2014-02-07
    and return a blank page with the text ‘0’ on it.
    The url switches from NameOfThePage.php?news_ondate=2014-02-07 to wp-admin/admin-ajax.php?news_ondate=2014-02-07 when I switch months.

    Can you give me some help?

    Thanks in advance.
    Greetings
    Word P

    #2976
    Bartosz
    Keymaster

    Can we take a look at your site?

    #2981
    Word P
    Participant

    It’s not online yet. I run it localhost.

    Here’s the code that I use for my template.
    I also don’t have permalinks enabled in the settings of the plugin so that I can GET the ?news_ondate.
    I made this template because I wanted to show the users on what date and time the news was posted.
    Is there an easier way to accomplish this or am I on the right track?
    <?php dynamic_sidebar(‘Nieuws widgets’); ?> is a seperate widget space with the calendar widget in.

    <?php
    /*
    Template Name: News
    */
    session_start();
    get_header(); ?>
    <div id=”primary”>
    <div id=”content” role=”main”>
    <?php

    $paged = ( get_query_var( ‘paged’ ) ) ? get_query_var( ‘paged’ ) : 1;
    // $wp_query = new WP_Query( array ( ‘post_type’ => ‘news’, ‘posts_per_page’ => ‘5’, ‘paged’ => $paged ));

    $sel = 0;
    if(isset($_GET[‘news_ondate’]))
    {

    $periode = trim($_GET[‘news_ondate’]);

    if(isset($_SESSION[‘hulpperiode’]))
    {
    if($periode <> $_SESSION[‘hulpperiode’])
    $paged = 1;
    }

    $_SESSION[‘hulpperiode’] = $periode;
    $jaar = substr($periode,0,4);
    $maand = substr($periode,5,2);
    $dag = substr($periode,8,2);

    $wp_query = new WP_Query(array
    ( ‘post_type’ => ‘news’, ‘posts_per_page’ => ‘5’, ‘paged’ => $paged,
    ‘date_query’ => array(
    array(
    ‘year’ => $jaar,
    ‘month’ => $maand,
    ‘day’ => $dag,
    ),
    )
    ));

    $sel = 1;

    }
    else
    {
    $wp_query = new WP_Query( array ( ‘post_type’ => ‘news’, ‘posts_per_page’ => ‘5’, ‘paged’ => $paged ));
    }

    print (“</BR>”);

    if($sel == 1)
    {
    print “Berichten op $dag-$maand-$jaar”;
    print (“</BR>”);print (“</BR>”);
    }

    while ($wp_query->have_posts()) : $wp_query->the_post();

    print (“<table width=100%><tr><td width=100% class=\”nieuwstitel\”>”);the_title();print (“</td></tr>”);
    print (“<tr><td class=\”nieuwsgepostop\”>Gepost op: “);the_time( ‘d/m/Y H:i’, ”); print (“</td></tr>”);
    print (“<tr><td><hr></td></tr>”);
    print (“<tr><td>”);the_content(); print (“</td></tr>”);
    print (“<tr><td><BR></td></tr>”);

    endwhile;

    print (“</TABLE>”);?>

    <?php if ($paged > 1)
    { ?>

    <nav id=”nav-posts”>
    <div class=”prev”><?php next_posts_link(‘« Vorige posts’); ?></div>
    <div class=”next”><?php previous_posts_link(‘Nieuwere posts »’); ?></div>
    </nav>

    <?php
    } else
    { ?>

    <nav id=”nav-posts”>
    <div class=”prev”><?php next_posts_link(‘« Vorige posts’); ?></div>
    </nav>

    <?php
    }
    wp_reset_postdata(); ?>

    </div><!– #content –>
    </div><!– #primary –>

    <div id=”secondary” class=”widget-area” role=”complementary”>
    <?php dynamic_sidebar(‘Nieuws widgets’); ?>
    </div>

    <?php //get_sidebar(”); ?>
    <?php get_footer(); ?>

    Greetings
    Word P

    #2988
    Bartosz
    Keymaster

    Oh man, that’s a mess (sorry for that :). For example, it would be better to use cookies instead of sessions. It may cause some trouble in WP.

    Did you try enabling permalinks (based on postnames)?

    #2996
    Word P
    Participant

    Is the coding so bad?
    Besides from using a session instead of a coockie, which parts can be improved?
    Actually all I want to do is add the date and time that a news item was made to the page.
    When I enable permalinks in the settings of the news manager and add %postname% to it,
    it goes to this URL: /postname/2014/02/07/ and shows the posts for that date.
    But it didn’t load my template page so it doesn’t show the date and time that the news item was added nor the calendar widget.
    I’m starting to think that there’s an easier way to accomplish all this,
    even with permalinks enabled in the settings of the plugin.
    Can you give me some help?

    Thanks in advance.
    Greetings
    Word P

    #3001
    Bartosz
    Keymaster

    Ok, I think I see the problem now.

    You don’t need to create page template. The plugin creates custom post type named “news”. It displays news archive using archive.php and single news using single.php (exactly like native posts).

    If you wan’t to use separate templates for news just follow the info from Codex – https://codex.wordpress.org/Template_Hierarchy. Create archive-news.php and/or single-news.php files in your theme and adopt it to your needs.

    You can of course use page template and custom query to display news list, but it will not handle the date attribute (news_ondate) automatically (what should be done if you display news in archive). As usually with WordPress, this could be overriden as well :) but that’s a different story…

    #3010
    Word P
    Participant

    Thanks for the info!
    I created the pages like you said and everything is working fine now.
    I enabled the permalinks in the plugin and referred it to the pagename where
    I want to display the news. ( Or can I display the news on a page in a different way? )
    Just one last question.
    What if I want to display the news on more than one page?
    How does this work as I can only fill in one word in the permalinks settings.
    Sorry if these are obvious questions but when I search for it online I keep bumping into “Templates”
    and that’s just what I’m trying to avoid.

    #3020
    Bartosz
    Keymaster

    There is only one archive for post type. If you’d like to display news on different pages you can use custom WP query just like you did above.

    #3027
    Word P
    Participant

    Thanks for all the help!
    Everything is working like it should be and my code looks much cleaner :)

    Thanks again.
    Greetings
    Word P

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.