trying to use Template tags and the loop
Ok im new to wordpress and php,
What im trying to do is pull Posts with their name, date and content. but i just cant understand how to use the tags and loop because i keep getting some Fatal error and i believe its because i did move around some files.
i know the way my files are set up. but how do i set where for the get_header or something to look because i installed wordpress as its our directory. such as http://www.site.com/wordpress and i want my index of site.com to pull posts from wordpress.
To make WordPress available at http://www.site.com just change in Settings->General, the Blog address (URL) to http://www.cite.com and put this index.php file in your web-root folder (it is the same folder that contains the wordpress folder)
<?php /* Short and sweet */ define('WP_USE_THEMES', true); require('./wordpress/wp-blog-header.php'); ?>
Then update your permalinks in Settings->Permalinks.
all the code did that you gave me just displays the entire wordpress blog onto my site. http://dhsdrama.com/
i had changed the real blog page to http://dhsdrama.com/blog.php
and the login page is at http://dhsdrama.com/blog/ it didnt affect anything. i still just have no idea how to pull only post title, time and content.
This is code for example only if you copy it from here with the ‘ included it won’t work.Don’t copy any ‘
if your wordpress is installed at /blog
/* Short and sweet */
I assume you aren’t using wordpress to “run” the home page so I assume you need to use false. then try this code in the file that runs the home page for your website at http://dhsdrama.com/ Post this before the loop:
$limit = get_option(‘posts_per_page’);
$paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
query_posts(‘showposts=’ . $limit . ‘&paged=’ . $paged);
$wp_query->is_archive = true; $wp_query->is_home = false;
This is where the loop starts:
‘<?php if (have_posts()) : while (have_posts()) : the_post(); ?>’
this outputs the post title
‘<h2 id=”‘post-‘<?php the_ID(); ?>'”>”‘” rel=”bookmark” title=”Permanent Link to ‘<?php the_title(); ?>'”>”<?php the_title(); ?>’‘</h2>’
this gets the Post time, author and category
‘Posted on <?php the_time(‘F jS, Y’) ?> by <?php the_author() ?> in <?php the_category(‘, ‘) ?>’
finally the loop
if you want an excerpt to show
‘<?php the_excerpt() ?>’
if you want all content to show
‘<?php the_content() ?>’
you probably have some html divs to close before closing the loop so close them here or else the divs break
then close the loop-sorry this is older code you can find newer ending loop code in the codex but this should still work
‘<?php endwhile; ?>’
‘<?php else : ?>’
‘<?php endif; ?>’
then close the main div the one that wraps all the main content on the page:
then get the footer
‘<?php get_footer(); ?>’
I hope this works out for you.You should definitely read up on the codex and google using wp_blog_header.php in non wordpress page.
- The topic ‘trying to use Template tags and the loop’ is closed to new replies.