WordPress.org

Ready to get started?Download WordPress

Forums

generate a newsletter of wordpress posts per month (5 posts)

  1. newty
    Member
    Posted 3 years ago #

    Hi,

    I would like to generate a newsletter of wordpress posts (title post + excerpt or content + title of category) of last month.

    So, I generate a new file in php (with fopen, fwrite, etc...) in which I put template code. But I have a problem to generate posts.

    I've made required of major files :

    require_once("/mon-ndd/www/wp-config.php");
    require_once("/mon-ndd/www/wp-load.php");
    require_once("/mon-ndd/wp-includes/wp-db.php");

    When I put this function : `get_archives('postbypost', '10', 'custom', '
    <li>', '</li>
    ');`

    it runs but not with this code for example :

    while (have_posts()) : the_post();
      // the content of the post
      the_content('Read the full post ยป');
    endwhile;

    Do you know why ?

    Thank for you help.

  2. newty
    Member
    Posted 3 years ago #

    up ! :)

  3. newty
    Member
    Posted 3 years ago #

    I've test in command line on my server with : php -f /var/mon-ndd/www/newsletters/genere-newsletter.php but I havn't warnings / errors...

  4. newty
    Member
    Posted 3 years ago #

    I've added a if (have_posts()) and result is "Sorry, no post published".

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <h2>" href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></h2>
    <?php the_content(); ?>
    <?php endwhile; else: ?>
    <p>Sorry, no post published.</p>
    <?php endif; ?>

    So, there is no post for it... Do I have to include another php file ?

  5. newty
    Member
    Posted 3 years ago #

    I've found ! I've added query_posts

    But I cannot write wordpress data in my file. For example, there, $permalink and $title are displayed on my screen but are not writted in the file. Do you know how can I resolve this problem ?

    while (have_posts()) : the_post();
    fwrite($fp, '<tr>');
    fwrite($fp, '<td>');
    fwrite($fp, '<p>');
    fwrite($fp, '<a href="');
    $permalink = the_permalink();
    fwrite($fp, $permalink);
    fwrite($fp, '">');
    $title = the_title();
    fwrite($fp, $title);
    fwrite($fp, '');
    fwrite($fp, '</p>');
    fwrite($fp, '</td>');
    fwrite($fp, '</tr>');
    endwhile;

    Thanks to you :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.