I am using OptionTree for WordPress option panel, I am getting the page ID, and using that page ID I want to populate the content of the page to another page. Here is my code:
<?php
$test_input = ot_get_option( 'for_myapp_features' );
?>
<?php $the_query = new WP_Query( 'page_id=$test_input' ); ?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<?php the_title(); ?>
<?php the_excerpt(); ?>
<?php endwhile;?>
Any help would be helpful.
You can use get_post_field and get_the_title() to get
content and title.
$test_input = ot_get_option('for_myapp_features');
echo get_post_field('post_title', $test_input); // to get the title
//or
//echo get_the_title($test_input); // to get the title
echo get_post_field('post_content', $test_input); //to get the content
Hope this helps!
If you want to display the content for that page, then add the_content() within your while loop. the_content() will display the page’s content. I would also add a query reset, wp_reset_query();, after the endwhile to restores the global post data to the original query.
Related
I'm using a theme that uses the blog page to display all of its content on the blog page rather than an excerpt and then when i click into the post i want to show the whole content.
I'm using the following code:
$postId = get_the_ID();
$ex = the_excerpt();
if($postId == 19){
echo $ex;
}
else{
echo $content;
}
The blog page is located at post =19
I would expect only the excerpt to show on the blog page and the content to show on the post page. However both show. Also it doesnt matter if i change the number 19 in my if statement as the same happens. Can anyone see where i am going wrong?
edit made changes, screen shots:
You need to use the_excerpt(); inside the condition means where you want to display the excerpt but in case you want to get value of excerpt but does not want to display it directly then you have to use get_the_excerpt(); so you need to change
$ex = the_excerpt();
to
$ex = get_the_excerpt();
And same is the case with the_content()
Hope it helps you.
functions such as the_excerpt() are only available inside the loop or after you call the function the_post()
You may want to display only the except in your index.php
while (has_posts()) {
the_post();
the_excerpt();
}
In your single.php you may want to display the whole content
if(has_posts()) {
the_post();
the_content();
}
Use $postId = get_queried_object_id(); instead of $postId = get_the_ID();
I've run into a bit of a wall with a site I'm designing for a client. This was originally a very low budget static site but the client now needs the ability to edit some content from time to time. I've heard that you can just embed a wordpress page into existing HTML site and have followed the steps on the Codex site but can't seem to get it working. Any help is greatly appreciated.
So the wordpress page I'm trying to embed is the following:
http://octagonclubmiami.com/cs/
And the code I'm using is as follows:
This is posted at the beginning of the php file
<?php
/* Short and sweet */
define('WP_USE_THEMES', false);
require('cs/wp-blog-header.php');
?>
And this is within the body of the php file
<?php
$posts = get_posts('numberposts=10&order=ASC&orderby=post_title');
foreach ($posts as $post) : setup_postdata( $post ); ?>
<?php the_date(); echo "<br />"; ?>
<?php the_title(); ?>
<?php the_excerpt(); ?>
<?php
endforeach;
?>
The actual page I'm trying to embed into is the following:
http://octagonclubmiami.com/community_service_test.php
As it sits it's currently displaying I guess some sample post instead of the page mentioned earlier.
Thanks in advance!
The better solution (I think) is to use get_post() and specify the ID number of the post/page you wish to output:
<?php
$page = get_post( 'ID NUMBER HERE' );
setup_postdata( $page );
?>
<?php the_date(); echo "<br />"; ?>
<?php the_title(); ?>
<?php the_excerpt(); ?>
You can identify the post's ID number in the WordPress back-end.
I can’t figure out why this won’t work? I have more than 15 posts but they’re getting cut off the page.
The site: http://gruntsandco.com/
My loop:
<?php $latest = new WP_Query('showposts=15'); ?>
<?php while( $latest->have_posts() ) : $latest->the_post(); ?>
Loopageness
<?php endwhile; ?>
You can try 'posts_per_page' attribute for WP Query.
<?php $latest = new WP_Query('posts_per_page=15'); ?>
<?php while( $latest->have_posts() ) : $latest->the_post(); ?>
Loopageness
<?php endwhile; ?>
If you want to show all posts just set this parametr to -1.
I am trying to post the data from a form submitted on the last page by each ID of the available posts on the current page. I thought this ought to work on the wordpress platform but it hasn't any ideas. the_ID() is a wordpress shortcode for picking up the current post ID.
<?php query_posts('post_type=services'); while (have_posts()) : the_post();
$title = $_POST["product_title_PRI_".the_ID()];
echo $title ;?>
Marvellous
ANSWER get_the_ID()
<?php query_posts('post_type=services'); while (have_posts()) : the_post();
$title = $_POST["product_title_PRI_".get_the_ID()];
echo $title ;?>
Seems like the problem with this is the PHP syntax, but no luck in Wordpress forums. This first code block generates a link to the newest post in category "posts."
<?php $my_query = new WP_Query('category_name=posts&showposts=1'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php the_title(); ?>
<?php endwhile; ?>
This next code block should display the custom field data for the latest post in "posts," with the key of the custom field being "qanda." But it doesn't and it displays nothing.
<?php $my_query = new WP_Query('category_name=posts&showposts=1'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php echo get_post_meta($post->ID, "qanda", $single = true); ?>
<?php endwhile; ?>
Thanks, Mark
try renaming your second query, otherwise Wordpress will think it is already done
<?php
$my_other_query = new WP_Query('category_name=posts&showposts=1');
while ($my_other_query->have_posts()) : $my_other_query->the_post();
echo get_post_meta($post->ID, "qanda", true);
endwhile;
?>
Apart fromthat $single = true should just be true it looks OK... try var_dump instead of echo and see what you get.
You might need to name it something different. Wordpress might think that you have already done that set of posts, so it is starting at the end, which means it doesn't have anymore posts to process.