Display Post in wordpress through PHP Code - wordpress

i have prepare a scroller and need to show in footer of the wordpress page. it has provided me an ID, not able to show it in footer file, its display as it code which i have putted it in post page.Using the below Plugin http://www.gopiplus.com/work/2011/05/08/wordpress-plugin-image-horizontal-reel-scroll-slideshow/#.UKX1ie-0Ndg
I have applied the code in post as [ihrss-gallery type="gallery1" w="600" h="170" speed="1" bgcolor="#FFFFFF" gap="5" random="YES"]
Any help ?
I am using below code --
<?php
$post_id = 11893;
$queried_post = get_post($post_id);
$title = $queried_post->post_title;
echo $queried_post->post_content;
?>

You'll need to use the Loop first before using the post_content like that
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<!-- do stuff ... -->
<?php endwhile; ?>
<?php endif; ?>
Follow this guide
http://codex.wordpress.org/The_Loop

For more details of get_post click this link -
http://codex.wordpress.org/Function_Reference/get_post
$my_id = 297;
$post_id_7 = get_post($my_id);
$title_7 = $post_id_7->post_title;
echo $title_7;
$content_7 = $post_id_7->post_content;
echo $content_7;

Related

how to get wordpress post tags using fishpig in magento

I am unable to fetch post tags added from wordpress admin panel. I am using fishpig magento extension and everything is working perfectly.
I am fetching posts using the code
$posts = $this->getPosts();
and I need tags associated with each post.
Please help.
You can get the tags for an individual post by calling the getTags method on the post object. Here is a snippet pertaining to post tags from the post view template:
<?php $tags = $post->getTags() ?>
<?php if (count($tags) > 0): ?>
<span><?php echo (count($categories) == 0) ? $this->__('This post was tagged with') : $this->__('and was tagged with') ?> </span>
<?php $it = count($tags) ?>
<?php foreach($tags as $tag): ?>
<a href="<?php echo $tag->getUrl() ?>">
<?php echo $tag->getName() ?>
</a><?php if (--$it > 0): ?>, <?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
You have a collection of posts rather than a single post, you can call getTags on an individual post as you are iterating over your collection.
foreach($posts as $post) {
$tags = $post->getTags();
}

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();
}

Next / Prev post link not working wp

Ok so I am having issues with linking to next and previous posts...
Here is my code:
<?php get_header(); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
...
<div id="project-prev"> <?php previous_post_link('Prev'); ?> </div>
<div id="project-next"> <?php next_post_link('Next'); ?> </div>]
...
<?php endwhile; // end of the loop. ?>
<?php endif; ?>
<?php get_footer(); ?>
I have read places that next/prev posts requires a 'new WP_Query' query, but have had no such luck. There is no next/prev link rendered out on my site, using the above.
As always appreciate solutions and pointers.
Many thanks
Have you tried following (according to Wordpress codex)
<?php next_post_link('<strong>%link</strong>'); ?>
<?php previous_post_link('<strong>%link</strong>'); ?>
In your divs ... :) If you still encouter problems, then just try something like:
<?php echo get_previous_posts_link('Prev'); ?>
<?php echo get_next_posts_link('Next'); ?>
Should work.
EDIT:
<div id="project-prev"><?php previous_post_link('%link', 'PREV'); ?></div>
<div id="project-next"><?php next_post_link('%link', 'NEXT'); ?></div>
First try and get the next and previous posts.
<?php
$previous_post_url = get_permalink(get_adjacent_post(false, '', true));
$next_post_url = get_permalink(get_adjacent_post(false, '', false));
?>
And then create to <a> tags and echo out the URLs we set above.
<?php if ( $previous_post_url != get_the_permalink() ) : ?>
Previous Project
<?php endif; ?>
<?php if ( $next_post_url != get_the_permalink() ) : ?>
Next Project
<?php endif; ?>
One reason that could make these links not to show is having the posts set as draft. Only published posts will make the previous and next post links render.

How to apply pagination for a custom WordPress query?

<?php $query = new WP_Query('posts_per_page=1&'); ?>
<?php while ($query->have_posts()) : $query->the_post(); ?>
<?php the_title(); ?><br />
<?php echo paginate_links( $args ) ?>
<?php endwhile;?>
<?php wp_reset_postdata(); ?>
Here is the query I'm using, it should display the first post title then displays the pagination links, however it only shows the post title without the pagination links. What's wrong?
The paginate_links function should go outside the loop and you should use the query variable "paged"
Please see this link http://scribu.net/wordpress/wp-pagenavi/right-way-to-use-query_posts.html for more information on using this.

posts pagination in wordpress

i want to show 4 posts in page and after 4 posts it will show next button to read next posts.
<?php while (have_posts()) : the_post(); ?>
<?php
global $post;
$myposts = get_posts('numberposts=4&order=ASC&category=3');
foreach($myposts as $post) :
setup_postdata($post);
?>
here is content with html
<?php endforeach; ?>
<?php endwhile; ?>
<?php endif; ?>
You just need to add paged parameter to your query_posts:
$myposts = get_posts('numberposts=4&order=ASC&category=3&paged' . get_query_var('paged'));
And add post_nav_link() to display next and prev link.
<?php posts_nav_link(); ?>
Cheers, oh, btw, you can post specific wordpress question at wordpress.stackexchange.com.

Resources