WordPress.org

Ready to get started?Download WordPress

Forums

trying to use Template tags and the loop (5 posts)

  1. bbobby707
    Member
    Posted 5 years ago #

    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.

  2. MichaelH
    Member
    Posted 5 years ago #

    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.

  3. bbobby707
    Member
    Posted 5 years ago #

    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.

  4. mccormicky
    Member
    Posted 5 years ago #

    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
    try '<?php
    /* Short and sweet */
    define('WP_USE_THEMES', false);
    require('./blog/wordpress/wp-blog-header.php');
    ?>'

    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:

    call header
    '<php get_header.php();?>'
    '<div id="content">'
    '<?php
    $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(); ?>'
    '<div class="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
    '<div class="entry">'
    '<?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
    ie '</div>'
    & '</div>'
    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:
    </div>
    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.

  5. mccormicky
    Member
    Posted 5 years ago #

    Sorry can't seem to get the post title code to show.

Topic Closed

This topic has been closed to new replies.

About this Topic