Wordpress: show comment on a new page? - wordpress

I need to display link after each comment, when you click that link, a new page displays that single coment on a new page.
Is that possible?

I answered your exact question over on WordPress Answers (also a StackExchange site) just yesterday. You can find that answer here. It involved the following four steps:
Setting up the URL Rewriting by adding a query_var, rewrite_tag and a permastruct,
Being sure to flush the rewrite rules in a plugin's activation hook or manually,
Adding a parse_query filter hook to set the query_vars's post to be the comment's post and to disable sticky posts for the query,
Adding a template_include filter hook to filter the template file name to load a template specific template file for a single comment, and lastly
To create the comment template file as /wp-content/themes/%your-theme%/comment.php.
Again, you can find the answer over here.
Hope this helps.
-Mike
UPDATE:
Below is the full content that I had also posted on WordPress Answers:
There are numerous different ways to accomplish this, some more polished than others and practically all of them with potential for conflict with other plugins, but ignoring all that here's one way that is pretty close to what you asked for. :)
This solution will support a URL format like the following where %comment_id% is the numeric ID of your comment from the wp_comments table:
http://example.com/comments/%comment_id%/
First you'll need to configure your URL rewriting using the following code. Hopefully it is reasonably self-explanitory but don't hesitate to ask:
$wp->add_query_var('comment_id'); // Add the "behind-the-scenes" query variable that WordPress will use
$wp_rewrite->add_rewrite_tag('%comment_id%', '([0-9]+)','comment_id='); // Define a rewrite tag to match that assigns to the query var
$wp_rewrite->add_permastruct('comment-page', 'comments/%comment_id%'); // Define a URL pattern to match the rewrite tag.
You'll also either need to call this code in a plugin activation hook to flush the rules, or if it's your site you can just save permalinks in the admin console's Settings > Permalinks settings area:
global $wp_rewrite;
$wp_rewrite->flush_rules(false);
Next add a parse_query filter hook. This will be called after WordPress has inspected the query. It tests to see if your added comment_id query_var set and if so it tests to see if you are on the desired URL. If yes then it loads the comment array using get_comment() in order to set the 'p' parameter (which should be set to a post ID) to the post that is related to the comment. That way when WordPress runs the query that it is going to run no matter what at least it loads something you'll need in your comment.php theme template file below and you won't have to ran another query later when you need it. This code also tells WordPress to ignore sticky posts using the oddly named caller_get_posts option:
add_filter( 'parse_query', 'my_parse_query' );
function my_parse_query( $query ) {
global $wp;
if (isset($query->query['comment_id']) && substr($wp->request,0,9)=='comments/') {
$comment = get_comment($query->query['comment_id']);
$query->query_vars['p'] = $comment->comment_post_ID; // Causes the comment's post to be loaded by the query.
$query->query_vars['caller_get_posts'] = true; // Keeps sticky posts from invading into the top of our query.
}
}
Still next you'll need to hook the code in /wp-includes/template-loader.php using the template_include filter. This will be called after WordPress has both inspected the query and loaded the post for the comment. Here you'll first check again for comment_id in the query_var and also for the URL being the one you want. If so we replace the /index.php template page with /comment.php which is a theme template file you will need to create:
add_filter( 'template_include', 'my_template_include' );
function my_template_include( $template ) {
global $wp,$wp_query;
if (isset($wp_query->query['comment_id']) && substr($wp->request,0,9)=='comments/') {
$template = str_replace('/index.php','/comment.php',$template);
}
return $template;
}
Lastly now you need to create your theme template file which I've chosen to call /comment.php. Since it's your theme you'll want to make it look like you want but here is an example to get you started:
<?php
/*
* File: /wp-content/themes/my-theme/comment.php
*/
global $wp_query,$post;
$comment_id = $wp_query->query['comment_id'];
$comment = get_comment($comment_id);
$permalink = get_permalink($post->ID);
get_header();
?>
<div id="container">
<div id="comment-<?php echo $comment_id; ?>" class="comment">
<p>Comment by: <span class="comment-author">
<?php echo $comment->comment_author; ?></span>
on <span class="comment-date"><?php echo date("D M jS Y", strtotime($comment->comment_date)); ?></span>
at <span class="comment-time"><?php echo date("h:ia", strtotime($comment->comment_date)); ?></span>
</p>
<p>About: <?php echo $post->post_title; ?></p>
<blockquote><?php echo $comment->comment_content; ?></blockquote>
</div>
</div>
<?php
get_sidebar();
get_footer();
Any questions? Just ask.
Hope this helps.
P.S. All of the code I describing above can either go in your theme's functions.php file and/or in a plugin of your own. A caveat is for the URL rewrite flushing rules that should go in a plugin activation hook if you are going to include it instead us just flushing them manually in the permalinks section of the admin console. I didn't show how to register an activation hook do but if you want to learn more you can read about it here.

(New edited version after OP's comments)
There are many ways to do this. In theory this is the simplest, but maybe not 'most appropriate according to WordPress' way. Take this as a starting point. I haven't tested it, so you may encounter an error or two that should be solvable with some minor tweaks. Let me know if you get stumped and I'll do my best. So conceptually...
You should copy the page.php template file and rename it to 'comments_page.php' (or whatever you like). Open this file in your code editor and find where the following appears: (or create it if it does not exist)
/*Template Name: page*/
and change it to
/*Template Name: comments_page*/
Now open your WordPress admin area and create a new page. Call it whatever you want but don't add any content. In the right hand column, select the template that the page uses from the "Page Template" drop down menu. Select 'comments_page' (or whatever you listed as the template name). This tells WordPress to use your file to show this specific page instead of the default page template. Save the page and note the page_id that WordPress generates.
Now, find your theme's comments template, usually 'comments.php'. Find the function wp_list_comments();. We are going to add the name of a custom function that will control the display of your comments as an argument to this function. For an example, go to the twenty-ten theme's files, open comments.php and you'll see what that looks like:
wp_list_comments( array( 'callback' => 'twentyten_comment' ) );
Open the twenty-ten theme's functions.php and find
function twentyten_comment()
Copy that entire function and paste it into your theme's functions file. Change the name to' my_comment()', and add that to the wp_list_comments function call like this:
wp_list_comments( array('callback'=>'my_comment'));
In your newly-created 'my_comment()' function in your functions.php file, add a link where you want to the separate page of comments (comments_page.php) using get_page_link() and a query var named 'commentID' and the comments ID.
View this comment
Now to inappropriately add php logic to a template file. Once you understand how this works, you can create a function in your functions.php file and then call it in the theme file...
On comments_page.php ,use $_GET['commentID'] to retrieve the comment's id value from the url, and pass it to get_comment($commentID) to retrieve the single comment and display it on a single page.
if(isset($_GET['commentID'])){$commentID = $_GET['commentID'];}
$comment = get_comment($commentID);
Now you have all the single comments information in the $comment variable as an object.
You can decide how to display the comment, but to start, I recommend copying the contents of your theme's comments template to keep things consistent. It will show exactly the same thing the post page shows, but it sounds like this page is intended more for the permalink to a single comment that you link to from somewhere else.
Hope this helps. Let me know if you run into a snag.
Note: this answer provides info given to me from Todd Perkins over at wordpress.stackexchange.com

This is my functions.php
<?php
if ( ! function_exists( 'twentyten_comment' ) ) :
function my_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case '' :
?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
<div id="comment-<?php comment_ID(); ?>">
<div class="comment-author vcard">
<?php echo get_avatar( $comment, 40 ); ?>
<?php printf( __( '%s <span class="says">says:</span>', 'twentyten' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
</div><!-- .comment-author .vcard -->
<?php if ( $comment->comment_approved == '0' ) : ?>
<em><?php _e( 'Your comment is awaiting moderation.', 'twentyten' ); ?></em>
<br />
<?php endif; ?>
<div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
<?php
/* translators: 1: date, 2: time */
printf( __( '%1$s at %2$s', 'twentyten' ), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' );
?>
</div><!-- .comment-meta .commentmetadata -->
<div class="comment-body"><?php comment_text(); ?></div>
View this comment
<div class="reply">
<?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
</div><!-- .reply -->
</div><!-- #comment-## -->
<?php
break;
case 'pingback' :
case 'trackback' :
?>
<li class="post pingback">
<p><?php _e( 'Pingback:', 'twentyten' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __('(Edit)', 'twentyten'), ' ' ); ?></p>
<?php
break;
endswitch;
}
endif;
This is my comments_page.php
/*Template Name: comments_page*/
<? if(isset($_GET['commentID'])){$commentID = $_GET['commentID'];}
$comment = get_comment($commentID);
?>
<?php get_header(); ?>
<div id="content">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="post">
<!--uncomment for header tags-- <h1><?php the_title(); ?></h1>
<small><b>Posted:</b> <?php the_time('F jS, Y') ?> | <b>Author:</b> <?php the_author_posts_link(); ?> | <b>Filed under:</b> <?php the_category(', ') ?> <?php the_tags(' | <b>Tags:</b> ', ', ', ''); ?> <?php if ( $user_ID ) :
?> | <b>Modify:</b> <?php edit_post_link(); ?> <?php endif; ?>| <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></small> -->
<?php the_content('Read the rest of this entry »'); ?>
<hr/>
</div>
<?php endwhile; ?>
<div class="navigation">
<div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
<div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
</div>
<?php else : ?>
<h2 class="center">Not Found</h2>
<p class="center">Sorry, but you are looking for something that isn't here.</p>
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
This is my comments.php
<?php // Do not delete these lines
if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
die ('Please do not load this page directly. Thanks!');
if (!empty($post->post_password)) { // if there's a password
if ($_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie
?>
<p class="nocomments">This post is password protected. Enter the password to view comments.</p>
<?php
return;
}
}
/* This variable is for alternating comment background */
$oddcomment = 'class="alt" ';
?>
<!-- You can start editing here. -->
<div id="comments">
<?php if ($comments) : ?>
<h3><?php comments_number('No Comments', 'One Comment', '% Comments' );?> on “<?php the_title(); ?>”</h3>
<?php wp_list_comments( array('callback'=>'my_comment')); ?>
<?php else : // this is displayed if there are no comments so far ?>
<?php if ('open' == $post->comment_status) : ?>
<!-- If comments are open, but there are no comments. -->
<?php else : // comments are closed ?>
<!-- If comments are closed. -->
<p class="nocomments">Comments are closed.</p>
<?php endif; ?>
<?php endif; ?>
<?php if ('open' == $post->comment_status) : ?>
<hr/>
<h4 class="center">Leave a Reply</h4>
<?php if ( get_option('comment_registration') && !$user_ID ) : ?>
<p>You must be logged in to post a comment.</p>
<?php else : ?>
<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
<ul class="formlist">
<?php if ( $user_ID ) : ?>
<p>Logged in as <?php echo $user_identity; ?>. Log out »</p>
<?php else : ?>
<li><input type="text" name="author" id="author" value="Name <?php if ($req) echo "(required)"; ?>" size="22" tabindex="1" <?php if ($req) echo "aria-required='true'"; ?> onblur="if(this.value.length == 0) this.value='Name <?php if ($req) echo "(required)"; ?>';" onclick="if(this.value == 'Name <?php if ($req) echo "(required)"; ?>') this.value='';" /></li>
<li><input type="text" name="email" id="email" value="Mail (will not be published) <?php if ($req) echo "(required)"; ?>" size="22" tabindex="2" <?php if ($req) echo "aria-required='true'"; ?> onblur="if(this.value.length == 0) this.value='Mail (will not be published) <?php if ($req) echo "(required)"; ?>';" onclick="if(this.value == 'Mail (will not be published) <?php if ($req) echo "(required)"; ?>') this.value='';" /></li>
<li><input type="text" name="url" id="url" value="Website" size="22" tabindex="3" onblur="if(this.value.length == 0) this.value='Website';" onclick="if(this.value == 'Website') this.value='';" /></li>
<?php endif; ?>
<!--<p><small><strong>XHTML:</strong> You can use these tags: <code><?php echo allowed_tags(); ?></code></small></p>-->
<li><textarea name="comment" id="comment" cols="70%" rows="10" tabindex="4" value="Enter comment here."></textarea></li>
<li class="submitbutton"><input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" /></li>
<input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />
<?php do_action('comment_form', $post->ID); ?>
</ul>
</form>
<?php endif; // If registration required and not logged in ?>
<?php endif; // if you delete this the sky will fall on your head ?>
</div>

Related

Remove Page Header from Blog Posts

I have a page-header that is getting copied over to all of my blog posts that I want to remove completely. I am removing it visually via CSS, but SEO crawlers are still picking it up via the tag.
I am using a standard wordpress them augmented with Elementor. Here is a screenshot of the SEO report.
And here is a screenshot of the actual HTML code
Let me know if any of you have any additional questions! Thank you for your help!
You can make a conditional statement that just outputs the title of the post if on single blog posts, so something like this
<div class="container clr page-header-inner">
<?php
// Return if page header is disabled
if ( oceanwp_has_page_header_heading() ) { ?>
<!-- check to see if single blog posts -->
<?php if (is_single()) : ?>
<h1><?php echo get_the_title(); ?></h1>
<!-- otherwise show the existing title format -->
<?php else: ?>
<<?php echo esc_attr( $heading ); ?> class="page-header-title clr"<?php oceanwp_schema_markup( 'headline' ); ?>><?php echo wp_kses_post( oceanwp_title() ); ?></<?php echo esc_attr( $heading ); ?>>
<?php endif; ?>
<?php get_template_part( 'partials/page-header-subheading' ); ?>
<?php } ?>
<?php if ( function_exists( 'oceanwp_breadcrumb_trail' ) ) {
oceanwp_breadcrumb_trail();
} ?>
</div><!-- .page-header-inner -->
you would have to replace the existing code

wordpress the_content not showing video

I am developing a separate website and for showing the blogs i am using the worpress.I have used following code to display blogs.It shows the textual contents properly but for video it just shows the player bar and not click able.
I have also checked themes index.php there is no the_excerpt.
When i check preview of the post using wordpress admin it shows the video properly.
can anyone help me resolve this?
here is my code..
<?php
global $more;
$posts = get_posts('category=3&numberposts=10&order=ASC&orderby=post_title');
foreach ($posts as $post) : setup_postdata( $post ); ?>
<?php $more = 1; ?>
<?php the_date(); echo "<br />"; ?>
<span style="color:#1C1644;font-size:1.3em !important;font-weight: bold;">
<?php the_title(); ?>
</span>
<div id="lol"><?php the_content(); ?>
</div>
<hr>
<?php
endforeach;
?>
Please try this
<?php
global $more;
$posts = get_posts('category=3&numberposts=10&order=ASC&orderby=post_title');
foreach ($posts as $post) :
setup_postdata( $post ); ?>
<?php $more = 1; ?>
<?php the_date(); echo "<br />"; ?>
<span style="color:#1C1644;font-size:1.3em !important;font-weight: bold;">
<?php echo the_title(); ?>
</span>
<div id="lol">
<?php echo the_content(); ?>
</div>
<hr>
<?php
endforeach;
?>
All you need to do to embed something into a post or page is to post the URL to it into your content area. Make sure that the URL is on its own line and not hyper-linked (clickable when viewing the post).
For example:
http://www.youtube.com/watch?v=dQw4w9WgXcQ
WordPress will automatically turn that into a YouTube embed when the post is viewed.
You can also optionally wrap the URL in the [embed] shortcode. It will accomplish the same effect, but does not require the URL to be on its own line.
It also allows you to set a maximum (but not fixed) width and height, like so:
[embed width="123" height="456"]http://www.youtube.com/watch?v=dQw4w9WgXcQ[/embed]
If WordPress fails to embed your URL you will get a hyper-link to the URL.
Use wp custom fields. Add video_embed custom field your post and add code.
<?php echo get_post_meta($post->ID, 'video_embed', true); ?>
Edit:
if(get_post_meta($post->ID, 'video_embed', true)){
echo get_post_meta($post->ID, 'video_embed', true);
}
else
{
the_content();
}

Wordpress Comment reply link does not appear

I am using custom code to print the comments but the problem is whatever i do, i cant print the comment reply link under any comment....
here is the code
<?php // Do not delete these lines
if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
die ('Please do not load this page directly. Thanks!');
if (!empty($post->post_password)) { // if there's a password
if ($_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie
?>
<p class="nocomments">This post is password protected. Enter the password to view comments.</p>
<?php
return;
}
}
/* This variable is for alternating comment background */
/*$oddcomment = 'class="alt" ';*/
$oddcomment = 'alt';
?>
<!-- You can start editing here. -->
<?php if ($comments) : ?>
<h3 id="comments"><?php comments_number('No Responses', 'One Response', '% Responses' );?> to “<?php the_title(); ?>”</h3>
<ol class="commentlist">
<?php foreach ($comments as $comment) : ?>
<!--<li <?php echo $oddcomment; ?>id="comment-<?php comment_ID() ?>">-->
<li class="<?php echo $oddcomment; ?> <?php if ($comment->comment_author_email == get_the_author_email()) { echo 'author_comment'; } ?>" id="comment-<?php comment_ID() ?>">
<?php echo get_avatar( $comment, 32 ); ?>
<cite><?php comment_author_link() ?></cite> Says:
<?php if ($comment->comment_approved == '0') : ?>
<em>Your comment is awaiting moderation.</em>
<?php endif; ?>
<br />
<small class="commentmetadata"><?php comment_date('F jS, Y') ?> at <?php comment_time() ?> <?php edit_comment_link('edit',' ',''); ?>
</small>
<?php comment_text() ?>
<div class="reply">
<?php comment_reply_link( array ( 'reply_text' => 'Reply this comment' ) );
?>
</div>
</li>
<?php
/* Changes every other comment to a different class */
/*$oddcomment = ( empty( $oddcomment ) ) ? 'class="alt" ' : '';*/
$oddcomment = ( empty( $oddcomment ) ) ? 'alt' : '';
?>
<?php endforeach; /* end for each comment */ ?>
</ol>
<?php else : // this is displayed if there are no comments so far ?>
<?php if ('open' == $post->comment_status) : ?>
<!-- If comments are open, but there are no comments. -->
<?php else : // comments are closed ?>
<!-- If comments are closed. -->
<p class="nocomments">Comments are closed.</p>
<?php endif; ?>
<?php endif; ?>
But when i use wp_list_comments functions i can see the reply link appear automatically i am using wordpress 3.2.1
It can be helpful to read the source for comment_reply_link (http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/comment-template.php#L1061), as there are multiple conditions that can lead to the link not appearing. Work through each one at a time, and you'll likely find your answer.
The one that tripped me up, is that the link will not appear if comments are closed. So it can be helpful to review the comment settings on the blog to make sure that providing replies is actually allowed on this post.
Try this:
comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth'])))
Thanks to the following codex-entry (http://codex.wordpress.org/Function_Reference/comment_reply_link), I managed to find the actual use of the comment_reply_link() on the following link: http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/comment-template.php#L1061
This leaves me with the following question - did you try adding either the second or the third parameter for the function? I think there might be something fishy going on under the hood, making the comment-link not know where to actually link.
Try removing the following snippet
comment_reply_link( array ( 'reply_text' => 'Reply this comment' ) );
and instead use the following one
comment_reply_link( array('reply_text' => 'Reply this comment'), comment_ID(), the_ID() );
Let me know if it works out for you!
Enable nested comments in Admin > Settings > Discussion:
Enable threaded (nested) comments levels deep

Make WordPress homepage a post category?

I am trying to set my WordPress homepage to a category but it only allows me to set it to either the latest posts or a static page.
Is it possible to set your homepage as a post category?
I am hoping that you know about how to set static page. So first create an empty .php file and name it whatever you like and put it along the other files (index.php, arhive.php etc).
and then enter following code
<?php
/*
* Template Name: Category based Homepage
*/
?>
<?php get_header(); ?>
<div class="main">
<?php
$cat_ID = '1'; //it should be your category ID, you can get the id of the category by going to categories and edit and then in url you can find the tag_ID.
$posts_to_show = '10'; // number of posts from the category you want to show on homepage
//query_posts("cat=$cat_ID&showposts=$posts_to_show");
$category_posts = new WP_Query("cat=$cat_ID&showposts=$posts_to_show");
//if (have_posts())
if ($category_posts->have_posts())
: $first = true;
?>
<ul class="post-list">
<?php
//while (have_posts()) : the_post();
while ($category_posts->have_posts()) : $category_posts->the_post();
if ($first)
$class = "first-in-row";
else
$class = "";
$first = !$first;
?>
<!-- Start: Post -->
<li <?php post_class($class); ?>>
<?php the_post_thumbnail(); ?>
<p class="categories"><?php the_category(", "); ?></p>
<h2><?php the_title(); ?> <?php edit_post_link(__('Edit', 'your_theme_text_domain'), '', ''); ?></h2>
<p class="post-meta"><span class="date"><?php the_time(get_option('date_format')) ?></span> <?php if (comments_open()) : ?>, <span class="comments"><?php comments_popup_link(_x('0', 'comments number', 'your_theme_text_domain'), _x('1', 'comments number', 'your_theme_text_domain'), _x('%', 'comments number', 'your_theme_text_domain')); ?></span> <?php endif; ?> <span class="author"><?php the_author() ?></span></p>
<?php the_excerpt(); ?>
<p class="more"><?php _e('Read More »» ', 'your_theme_text_domain'); ?></p>
<?php if (has_tag()): ?><p class="tags"><span><?php the_tags(""); ?></span></p><?php endif; ?>
</li>
<!-- End: Post -->
<?php endwhile; ?>
</ul>
<?php else : ?>
<h2 class="center"><?php _e('Not found', 'your_theme_text_domain'); ?></h2>
<p class="center"><?php _e('Sorry, but you are looking for something that isn\'t here.', 'your_theme_text_domain'); ?></p>
<?php
endif;
//wp_reset_query();
wp_reset_postdata();
?>
</div>
<?php get_sidebar(); //optional?>
<?php get_footer(); ?>
and replace $cat_ID and $posts_to_show to your liking. And I have used both query methods adjust it to your needs.
Hope it helps somebody who is looking for similar solution.
You can create a custom template that mimics a category page using get_posts and set a page using that template to home, but it won't be perfectly dynamic in the sense that you have to hard code the category slug or ID into that query. Assuming that you don't want to change that category often, that shouldn't be an issue. Alternatively, you could use wp_safe_redirect in a template to redirect to the category page - that would be if you want the user to be put directly on the real category page, URL and all.
I'm not sure what you mean by having your home page as a category, you mean that in your home page posts that will be displayed will be only from a certain category ?
You only need to perform a WP_Query before the loop;
$query = new WP_Query("cat=10, paged=".get_query_var('paged'));
Then use use the WP_Query object to perform the loop;
if($the_query->have_posts()):
while($the_query->have_posts()):
the_title();
the_content();
//Use all the loop function normally
endwhile;
endif;
The paged parameter is used to determine in which page you are, if you need paginantion.
Instead of using the category id, it is good to retrieve the id by the slug.
$home = get_category_by_slug('home-category-slug');
Then your query will be like this
$the_query = new WP_Query("cat=".$home->cat_ID.", paged=".get_query_var('paged'));
Yes this is possible Go to dashboard>>Setting>>Reading>>Static page Choose page from drop down and SAVE. On that page you can create your own stuff...

How can i have custom fields on the posts page in wordpress?

First I've created a home.php page to replace index.php and can add some custom fields on this new one and to have in it lastest 3 posts.
On home.php page I put:
<?php echo get_post_meta($post->ID, 'test', true); ?>"/>
but it doesn't works cause it tries get the post id and not the id of the page. If i put 18 (id of the page) directly it works, but i want it dinamicaly:
<?php echo get_post_meta(18, 'test', true); ?>"/>
And this condition is not satisfied for test:
if($post->post_type == 'page'){
echo 'This item is a page and the ID is: '.$post->ID;
}
Heyo,
I think your problem might be that you should have that within a loop.
For example if you were displaying several post from a category and displaying each custom field it might look like this:
<?php query_posts('cat=25&showposts=3'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li class="homeblock" style="max-width:400px;">
<span class="artist-name">
<?php $key='artist'; echo get_post_meta($post->ID, $key, true); ?>
</span>
<div class="entry-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
</li>
<?php endwhile; endif; ?>
Otherwise (not sure how your theme is set up), what you might have to do is edit content.php and add:
<?php $key='artist'; echo get_post_meta($post->ID, $key, true); ?>
Try:
if ($post->post_type == 'page') {
<?php echo get_post_meta($page_id, 'test', true); ?>
}
Hope this helps :)

Resources