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!
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!
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;
?>when i add that to my page (in the editor in html tab) it shows that code, how do i fix that?
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/
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
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?
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');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());
oh ok man thanks for explaining!
for some reason it doesn't work... it only shows 1 post, twice..
what can be the problem?
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);
haha yes indeed!
many thanks!
This topic has been closed to new replies.