I'm building a Wordpress template from an HTML page.
I currently have
<?php $queried_post = get_post( $_GET['id'], $output ); ?>
Then I use ...
<?php echo $queried_post->post_title; ?>
Which works fine for echoing the post title.
Then I try to echo the author with...
<?php echo $queried_post->post_author; ?>
I get back '1' which is not the author name. How is this done correctly?
Try this code:
<?php the_author($_GET['id']); ?>
Codex entry: http://codex.wordpress.org/Function_Reference/the_author
My single.php file:
<?php get_header(); ?>
<?php if (have_posts()): ?>
<?php while (have_posts()): the_post(); ?>
<div class="post post-single">
<h1 class="post-title">
<?php the_title(); ?>
<?php edit_post_link('Edit', '', ''); ?>
</h1>
<div class="content"><?php the_content(); ?></div>
</div>
<?php endwhile; else: ?>
There are no posts to display.
<?php endif; ?>
<?php get_footer(); ?>
Related
page-webinars.php:
<?php
/*
Template Name: Webinars
*/
?>
<?php
$loop = new WP_Query(array('post_type' => array('webinars')));
if ($loop->have_posts()) :
while ($loop->have_posts()) : $loop->the_post();
?>
<?php get_template_part('loop-webinars'); ?>
<?php endwhile; ?>
<?php endif;
wp_reset_postdata(); ?>
loop-webinars.php:
<?php the_title(); ?>
single-webinars.php:
<h1><?php the_title(); ?></h1>
<div>
<?php
the_post();
the_content();
?>
</div>
Looks like everything's correct. Page displays necessary template, but single not working.
You forget to use WordPress loop.
Try with this code in your single-webinars.php file.
<?php
// Start the loop.
while ( have_posts() ) : the_post();
?>
<?php the_title('<h1>', '</h1>'); ?>
<div>
<?php the_content(); ?>
</div>
<?php // End of the loop.
endwhile;
?>
It had just to "reactivate" theme...
I have integrated a HTML Template into Wordpress theme. In, menu area there is a menu called Blog. On click of that menu I want to show all the posts. On clicking some particular posts title one should go to the single post`s page. On that page there should be comments shown which are being posted earlier by some one as well as the comment form through which one can comment on that post.
Below is my blog.php code
<?php
/*
Template Name: Blog
*/
?>
<?php get_header(); ?>
<div id="inner_contant">
<div id="all_post">
<?php
$myposts = get_posts('');
foreach($myposts as $post) :
setup_postdata($post);
?>
<h2><?php the_title(); ?></h2>
<div class="author">Posted by <?php the_author(); ?></div>
<div class="post_excerpt"><?php the_excerpt(); ?></div>
<?php endforeach; wp_reset_postdata(); ?>
</div>
</div>
<?php get_footer(); ?>
Below is my single.php code
<?php
/*
* The template for displaying all single posts and attachments
*/
?>
<?php get_header(); ?>
<div id="single_post_wrap">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<div class="time_and_author"><?php the_time('F jS, Y') ?> by <?php the_author() ?></div>
<div class="post_content"><?php the_content(); ?></div>
<p>Posted in <?php the_category(', ') ?> | <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
<?php endwhile; endif; ?>
<?php foreach (get_comments() as $comment): ?>
<div><?php echo $comment->comment_author; ?> said: "<?php echo $comment->comment_content; ?>".</div>
<?php endforeach; ?>
<?php comments_template(); ?>
</div>
</div>
<?php get_footer(); ?>
Below is my comments.php code
<?php $comment_args = array(
'comment_notes_after' => '',
'title_reply' => 'Have something to say?'
) ?>
<?php comment_form($comment_args); ?>
I want to add some styling to that comment form. I have tried every thing but not worked for me. Thanks in advance for those who will help me.
WordPress' comment_form function prints a form with id 'commentform'. So you can use CSS to style this form.
form#commentform {
// your styles.
}
form#commentform input {
// your styles for inputs
}
/* default class of submit button is 'submit'. For changing it: add a
* key=>value to comment_form args like
* 'class_submit' => 'your_submit_class'
*/
form#commentform .submit {
// your submit button styles.
}
Also, you can change ID of comment form like this:
<?php $comment_args = array(
'comment_notes_after' => '',
'title_reply' => 'Have something to say?',
'id_form' => 'myAwesomeCommentForm'
) ?>
<?php comment_form($comment_args); ?>
I am currently using wordpress in creating my websites. And i really find a problem regarding pagination. So basically to be able for you to understand what is really my problem, I will post two codes:
This is the first code:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<?php include (TEMPLATEPATH.'/inc/meta.php'); ?>
<div class="entry">
<?php
the_excerpt();
?>
</div>
<br/><br/>
<h3>Read More...</h3>
</div>
<?php
endwhile;
?>
<?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
In this lines of code, I used the regular loop in querying a post. Actually I did not modify the code. I also installed a plugin WP-PageNavi. There is no problem, pagination is working properly.
But when i put this line of code, about the regular loop. Pagination is not working properly. I put this line of code " " because I want only to show post in this said category.
2nd code:
Line of code
<?php query_posts('cat=8'); ?>
End line of code
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
<div class="entry">
<?php the_excerpt(); ?>
</div>
<br/><br/>
<h3>Read More...</h3>
</div>
<?php endwhile; ?>
<?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
My question is: What should I do in order for the pagination to worked properly? I really need some help with this.
I think the problem is the because of the two The Loop(i.e while and endwhile loop) in a page.
instead of while use foreach loop. below is the example
<?php
$args = array('category' => '8');
$postArr = get_posts($args);
if($postArr){
foreach($postArr as $details){
?>
div <?php post_class() ?> id="post-<?php echo $details->ID; ?>">
<h2><?php echo $details->post_title; ?></h2>
<?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
<div class="entry">
<?php echo $details->post_excerpt(); ?>
</div>
<br/><br/>
<h3>Read More...</h3>
</div>
<?php
}
}else{
?>
<h2>Not Found</h2>
<?php
}
?>
Note Code not tested...
Now I've done this a couple other times with no problem, I have a main page using home.php and the blog as another page using "blog-home.php" blog template with all the right code to grab the posts but it's not displaying. The only difference is I've added a custom portfolio post field to the functions, would this be effecting it or could it be something else? I can access a post from the home page under latest post putting the code below but that's it.
<?php query_posts("post_per_page=1"); the_post(); ?>
<p><?php the_excerpt(); ?></p>
<?php wp_reset_query(); ?></div>
*UPDATE: I've tried another code but now it is only displaying the blog page as a post. *
<?php
/*
Template Name: Blog Home
*/
?>
<?php get_header(); ?>
<div id="contentwrapper">
<?php query_posts( array ( 'category_name' => 'Blog', 'posts_per_page' => 5 ) ); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<div class="blogentry">
<h4><?php the_title(); ?> </h4>
<?php the_content(); ?>
<div class="postmetadata">
<?php the_tags('Tags: ', ', ', '<br />'); ?>
</div>
<?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
</div>
</div>
<?php endwhile; ?>
<?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
</div>
<?php get_footer(); ?>
Maybe if you use
$posts = get_posts(array('numberposts' => 1));
global $post;
$post = $posts[0];
the_excerpt();
instead
query_posts();
is never a good idea change the global query if get_posts dosn't work for you try with WP_Query()
I am new to wordpress and i'm creating a site using wordpress.
You can see the mock up page here http://www.site2preview.com/veejata/ver1/index.html
And i've changed the index.php as
<?php
get_header();
//get_template_part( 'loop', 'index' );
?>
<div class="flt_left">
//dummy welcome text ..
</div>
<div class="flt_left">
//dummy latest post..
</div>
<?php get_sidebar(); ?>
<?php get_advt(); ?>
<?php get_footer(); ?>
Now i want to know how to create a custom page or block and how can i include them in the index.page..
Also i want the user should be able to edit the dummy welcome text from the admin panel..
In general i want to how to split the contents in the wordpress and how to make them editable by admin and how to include them in the pages...
This is what you should have in your simple index.php file (from wordpress classic theme):
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php the_date('','<h2>','</h2>'); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h3 class="storytitle"><a href="<?php the_permalink() ?>" rel="bookmark">
<?php the_title(); ?></a></h3>
<div class="meta"><?php _e("Filed under:"); ?> <?php the_category(',') ?>
— <?php the_tags(__('Tags: '), ', ', ' — '); ?>
<?php the_author() ?> #
<?php the_time() ?> <?php edit_post_link(__('Edit This')); ?></div>
<div class="storycontent">
<?php the_content(__('(more...)')); ?>
</div>
<div class="feedback">
<?php wp_link_pages(); ?>
<?php comments_popup_link(__('Comments (0)'),
__('Comments (1)'), __('Comments (%)')); ?>
</div>
</div>
<?php comments_template(); // Get wp-comments.php template ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
I would suggest you to read this first: http://codex.wordpress.org/Theme_Development