Web Design Forum: Latest wordpress post onto php page? - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Latest wordpress post onto php page? Rate Topic: -----

#1 User is offline   Lovelock 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 307
  • Joined: 12-May 11
  • Reputation: 7
  • Gender:Male
  • Location:Southampton, UK.
  • Experience:Intermediate
  • Area of Expertise:Designer

Posted 30 December 2011 - 03:57 PM

Hello, just need a bit of help.

I have a page that is a .php, and im trying to get my latest word press post to go into a div on that page.

My page is located at /page.php

and my wordpress at /blog

How can i go about this?
0

#2 User is offline   Lovelock 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 307
  • Joined: 12-May 11
  • Reputation: 7
  • Gender:Male
  • Location:Southampton, UK.
  • Experience:Intermediate
  • Area of Expertise:Designer

Posted 30 December 2011 - 04:04 PM

Was just a simple mistake on my behalf on not renaming the wordpress link -.-

Incase anyone wondered same as me,

added this to top of page ( i added just before the <body> tag:

<?php
// Include WordPress 
define('WP_USE_THEMES', false);
require('./blog/wp-load.php');
query_posts('showposts=1');
?>


Then this is how to pull the post from the blog:

            <?php while (have_posts()): the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
<p><a href="<?php the_permalink(); ?>">Read more...</a></p>
<?php endwhile; ?>


Still have a lot of styling to do but is a start!

Craig.
0

#3 User is offline   Lovelock 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 307
  • Joined: 12-May 11
  • Reputation: 7
  • Gender:Male
  • Location:Southampton, UK.
  • Experience:Intermediate
  • Area of Expertise:Designer

Posted 30 December 2011 - 04:30 PM

Actually...

Can anyone help me on reducing the amount of the post that is shown?

I only want to show say 1 / 2 lines.

I tried reducing the height of the div but the post remained 4 / 5 lines.

http://www.vinylpenguin.co.uk/page.php

Incase anyone wondered.
0

#4 User is offline   Nitin Reddy 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 55
  • Joined: 11-September 09
  • Reputation: 6
  • Gender:Male
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 30 December 2011 - 05:41 PM

View PostLovelock, on 30 December 2011 - 04:30 PM, said:

Can anyone help me on reducing the amount of the post that is shown?

I only want to show say 1 / 2 lines.


There are two things you have got to do to show only a part of an article. The first is to use the_excerpt(), as has been used in the code block you posted to this thread. The second is to add the "more" tag within the posts after the 1-2 lines that you want to display. I know, it is a manual process, but the alternative would be to do a substring or use CSS to hide text that does not fit within a DIV.
0

#5 User is offline   Lovelock 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 307
  • Joined: 12-May 11
  • Reputation: 7
  • Gender:Male
  • Location:Southampton, UK.
  • Experience:Intermediate
  • Area of Expertise:Designer

Posted 30 December 2011 - 06:06 PM

Just finished making this work. In the theme of wordpress, there is a file called function.php.

Incase anyone was wondering again...

function custom_excerpt_length( $length ) {
	return 20;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users