Forums

How do i make a list of all posts on a page? (13 posts)

  1. Jonas_
    Member
    Posted 1 year ago #

    Hello,

    i have a page called articles, and i want to have all the posts, no matter what category or date or whatever..

    i tried adding in the html of the page

    <?php
    query_posts();
    ?>

    but that doesn't work.. anyone can help me?

    thanks!

  2. jimmyt1988
    Member
    Posted 1 year ago #

    source: http://codex.wordpress.org/The_Loop

    <?php
       if ( have_posts() ) : while ( have_posts() ) : the_post();
    ?>
          <h2><?php the_title(); ?></h2>
          <?php the_content(); ?>
    <?php
       endwhile;
       endif;
    ?>
  3. Jonas_
    Member
    Posted 1 year ago #

    when i add that to my page (in the editor in html tab) it shows that code, how do i fix that?

  4. alchymyth
    The Sweeper
    Posted 1 year ago #

    you either make a page template for that page:
    http://codex.wordpress.org/Pages#Page_Templates

    or work with a plugin to allow php code in posts/pages
    for instance
    http://wordpress.org/extend/plugins/exec-php/

  5. Praveen
    Member
    Posted 1 year ago #

    Hello,

    You create a page template file, and insert what Jimmy has given. And then you use that template for the particular page.

    Please read this: http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates

    Regards

  6. Jonas_
    Member
    Posted 1 year ago #

    i tried using the functions class:

    function create_post_list() {
    	$text = '';
       if ( have_posts() ) : while ( have_posts() ) : the_post();
    	$text = '<h2> the_title(); </h2>';
          	$text .= the_content();
          	$text .= '<br />';
       endwhile;
       endif;
    	return $text;
    }
    add_shortcode('post_list', 'create_post_list');

    but for some reason it doesn't work when i add [post_list] to my page.. what is wrong?

  7. alchymyth
    The Sweeper
    Posted 1 year ago #

  8. Jonas_
    Member
    Posted 1 year ago #

    i don't understand what i have todo with the WP Query?

    Anyone can help me out?

    function create_post_list() {
    	$text = '';
       if ( have_posts() ) : while ( have_posts() ) : the_post();
    	$text = the_title('<h2>', '</h2>');
          	$text .= get_the_content();
          	$text .= '<br />';
       endwhile;
       endif;
    	return $text;
    }
    add_shortcode('post_list', 'create_post_list');
  9. alchymyth
    The Sweeper
    Posted 1 year ago #

    the wp_query link was for the parameter of the query, such as the number of posts, and to make sure you get all categories.
    if the code below is not working, you might need to add more parameter, such as post type...

    function create_post_list() {
    	$text = '';
    query_posts('cat=0&posts_per_page=-1');
       if ( have_posts() ) : while ( have_posts() ) : the_post();
    	$text = the_title('<h2>', '</h2>', false);
          	$text .= get_the_content();
          	$text .= '<br />';
       endwhile;
       endif; wp_reset_query();
    	return $text;
    }
    add_shortcode('post_list', 'create_post_list');

    if the result does not look 'good' try to replace this line:
    $text .= get_the_content();
    with:
    $text .= apply_filters('the_content', get_the_content());

    http://codex.wordpress.org/Shortcode_API

  10. Jonas_
    Member
    Posted 1 year ago #

    oh ok man thanks for explaining!

  11. Jonas_
    Member
    Posted 1 year ago #

    for some reason it doesn't work... it only shows 1 post, twice..

    what can be the problem?

  12. alchymyth
    The Sweeper
    Posted 1 year ago #

    a tiny dot . is missing (which i have overseen when posting the code)

    in this line before the = sign, to start the concatenation of the titles etc.

    $text = the_title('<h2>', '</h2>', false);

    has to be:

    $text .= the_title('<h2>', '</h2>', false);

  13. Jonas_
    Member
    Posted 1 year ago #

    haha yes indeed!

    many thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.