WordPress.org

Ready to get started?Download WordPress

Forums

Retrieving wordpress info (excerpt) via HTML or JavaScript? (5 posts)

  1. hscampbell
    Member
    Posted 9 years ago #

    Trying this question again because I think I posted in the wrong group. Or else no one has an answer :(

    I am using WP as the blog on my site, but the rest is in HTML as produced by Publisher.

    I can obviously add a hyperlink to the blog front page (index.html), but what I'd like to do is have a box on my site's (HTML) front page that has a post exerpt with a <!--more> tag or just a hyperlink to the blog page.

    I've searched but cannot find how I can do this. Am relatively new to both HTML and CSS, but have made good progress so far -- but am stumped on this one.

    Is it doable?

    Thanks in advance,
    hsc

  2. Kafkaesqui

    Posted 9 years ago #

    If the "front page" can be altered to a PHP document (i.e. index.php), adding content from WordPress is simple, because turning a regular page into a WordPress one just involves adding this right at the top:

    <?php
    require_once("./wp-blog-header.php");
    ?>

    If your blog resides in a subdirectory, say "/blog", then you change it to:

    <?php
    require_once("./blog/wp-blog-header.php");
    ?>

    Then to include a recent post on the front page, add something like this where you want it to appear:

    <?php
    $posts = get_posts('numberposts=1');
    foreach ($posts as $post) :
    start_wp();
    ?>
    <h3><a href="<?php the_permalink(); ?>"><?php the_title() ?></a></h3>
    <?php the_excerpt() ?>
    <?php
    endforeach;
    ?>

    Play with the layout--look at your blog's index template to see the tags you presently use on it.

  3. hscampbell
    Member
    Posted 9 years ago #

    Thanks, Kafkaesqui - This did work!

    It was easy to turn the index page into php, but I confess it took me several hours to figure out where in the file the extra code should go. I finally figured it out, though, and have it just like I wanted it (If you want to see it, it's at http://www.dialogicconsulting.com).

    It's a bit of a workaround, as Publisher automatically creates its own .pub files which are then automatically turned into HTML -- so I won't be able to reopen this in Publisher to edit; but since I only plan on having the extracts on the indext page (outside of the WP pages), now that I've kinda figured it out, I figure I can hand edit if I need to redesign or change content in Publisher.

    Again, thanks for the help!

  4. hscampbell
    Member
    Posted 9 years ago #

    A few more questions now that I'm in it:

    I switched to the_excerpt_reloaded so that I could limit the length of the content excerpts. It's working great except for two things
    (1) I have forced_more_link set to false -- the problem is that there's no return following excerpts that are less than what's been established -- so the next excerpt title doesn't start on a new line.
    (2) any ideas how to determine the width? I've tried tables, divs etc and can't make it seem to "listen" to the parameters.

    Any help appreciated :)

  5. jpepper
    Member
    Posted 8 years ago #

    Perfect. As always thank Kafkaesqui.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.