• Hi, this is my first post. I’ve been using various versions of WordPress for about two years now, without problems, but I’ve got a problem at the moment that I can’t work out.

    My website is distractionware.com, and the blog is in the subdirectory /blog/. The front page of my site has a one sentence summary of what’s currently happening on the site and a link to the different parts of it. I update this summary everytime I change something on the site, like a new blog post.

    I’m currently doing something a little weird here ?? I’m using phpBB forums and an extension for that called phpfetchall. It takes the content of a specific post on my forums and posts the text into the index.php on my frontpage.

    I’d like to get rid of that whole system by creating a page in wordpress and using some PHP functions to grab the text from that post. Is this difficult to do?

    For bonus points: Is there anyway to return the date and title of the most recent blog post? ??

Viewing 5 replies - 16 through 20 (of 20 total)
  • Okay, I think I’ll answer this call. ??

    <?php
    // My wordpress installation is in the wordpress sub folder
    // of the current directory
    require_once('./wordpress/wp-blog-header.php');
    
    // make sure the post exists
    if (have_posts ())
    {
     // output the title of the post
     the_title ();
    
     // output the time of the post
     the_time ();
    
     // fill the globals with the proper content
     the_post ();
    
     // display the content of the post
     the_content ();
    }
    ?>

    and here is a way you can format the display:

    <?php
    require_once('./wordpress/wp-blog-header.php');
    if (have_posts ())
    {
    ?>
    <div align="center" style="margin-top:128px;">
     <div align="center" style="font-family:arial; width:500px; border:4px; border-style:solid; border-color:#000000; padding:16px; padding-bottom:32px;">
    
      <div align="left"><h2><?php the_title (); ?></h2></div>
      <div align="right"><em><?php the_time (); ?></em></div>
    
      <?php the_post (); the_content (); ?>
     </div>
    </div>
    
    <?php
    }
    ?>

    Have fun.

    Hi Developer X

    Thanks for this code. I’ve almost got this working. I’m getting some unwanted lines in the webpage, see below:

    Test post 23:32 am

    Testing php headings

    Keith
    and here is a way you can format the display:
    Warning: main(./wordpress/wp-blog-header.php): failed to open stream: No such file or directory in /home/content/k/l/o/klogan/html/test.php on line 26

    Fatal error: main(): Failed opening required ‘./wordpress/wp-blog-header.php’ (include_path=’.:/usr/local/lib/php’) in /home/content/k/l/o/klogan/html/test.php on line 26

    ==

    Can you see what I’ve done wrong? I’m completely new to php.

    Thanks

    Thread Starter chaotic

    (@chaotic)

    Is your WordPress installation in the wordpress/ directory, relative to where you’re running the script?

    DevX sent me the full solution to this problem earlier today in the form of a little library, which you can get here:

    https://www.ccpssolutions.com/rmarks/Experimentations/devxlib_wp04-10-2007_224310.zip

    Hi

    I’m really new to this so I may have this setup all wrong.

    Ok, so I’ve used DevX sample file. That php file is located in the root of my hosting space. The WordPress installation is installed in a directory called ‘blog’

    Go to https://www.keithlogan.co.uk/devxlib_wp_example.php – do you see the error?

    Here’s the modified code from DevX:

    <?php
    require_once(‘./blog/wp-blog-header.php’);
    require_once(‘./devxlib_wp_example.php’);

    $l__content = devlib_get_content (1);

    ?>

    <div align=”center” style=”font-family:arial; margin-top:128px;”>

    <div align=”center” style=”font-family:arial; width:500px; border:4px; border-style:solid; border-color:#000000; padding:16px; padding-bottom:32px;”>
    <div align=”left”><h2><?php echo(devxlib_get_post_title($l__content)); ?></h2></div>
    <div align=”right”><?php echo(devxlib_get_post_date ($l__content)); ?></div>
    <?php echo(devxlib_get_post_content($l__content)); ?>

    </div>

    <small><?php echo bloginfo(‘name’); ?> – Powered by WordPress</small>
    </div>

    Do you see where I’ve gone wrong?

    Thanks

    Thread Starter chaotic

    (@chaotic)

    Not really ?? Sorry, I don’t see what that isn’t working.

Viewing 5 replies - 16 through 20 (of 20 total)
  • The topic ‘Is there an easy way to fetch the body from a specific post?’ is closed to new replies.