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();
}
Related
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
I have blog which is in sub directory and showing last post on static index page on main site.
main site -> http://example.com
blog -> http://example.com/wp
The blog post is showed correctly on main site but I can't show links for prev and next post/article. This is what I have an what I'm trying
<?php
define('WP_USE_THEMES', false);
require('wp/wp-blog-header.php');
$posts = get_posts('numberposts=1&order=ASC&orderby=post_title');
foreach ($posts as $post) : setup_postdata( $post ); ?>
<h1><?php the_title(); ?>
</h1><h2><?php the_date(); echo "<br />";?></h2>
<h3><?php the_content(); ?> </h3>
<div class="navigation"><p><?php posts_nav_link(); ?></p></div>
<?php endforeach; ?>
So this isn't visible: <div class="navigation"><p><?php posts_nav_link(); ?></p></div>
In Layman language it is a wordpress function to fetch posts/custom-posts. Internally it calls WP_Query function. Or you can use WP_Query instead of this. 'posts_nav_link' function does not work with WP_Query & get_posts function. You can try this to get next previous links.
$posts = get_posts('numberposts=1&order=ASC&orderby=post_title');
foreach ($posts as $post) : setup_postdata( $post ); ?>
<h1><?php the_title(); ?>
</h1><h2><?php the_date(); echo "<br />";?></h2>
<h3><?php the_content(); ?> </h3>
<?php endforeach; ?>
<div class="navigation">
<p><?php previous_post_link(); ?><?php next_post_link(); ?></p>
</div>
I cant comment you because I haven't enough reputations,
First follow https://codex.wordpress.org/Template_Tags/get_posts link
then check the sample code.
and also check the post display setting in the wp-admin panel /wp-admin/options-reading.php settings->reading section.
i'm trying to build a navigation for a website, and i'm struggling with it. I'm trying to make a foldable navigation that shows only categories at first, when clicked, they link to the category, and show current category posts only.
I came this far:
<?php
// get all the categories from the database
$cats = get_categories();
// loop through the categries
foreach ($cats as $cat) {
// setup the cateogory ID
$cat_id= $cat->term_id;
// Make a header for the cateogry
echo '<h2><a href="./?cat='.$cat->term_id.'">'.$cat->name.'</h2>';
// create a custom wordpress query
query_posts("cat=$cat_id");
// start the wordpress loop!
if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php // create our link now that the post is setup ?>
<?php the_title(); ?><br>
<?php endwhile; ?> <?php endif; // done our wordpress loop. Will start again for each category ?>
<?php } // done the foreach statement ?>
The problem with this is: when i fill in the query so that it only takes the current cat, it displays current cat posts on both my categories.
this is what i want for the nav actually:
graphic design
Other Projects
when clicked on graphic design:
graphic design
Project 1
Project 2
Other Projects
when clicking on Other projects:
graphic design
Other Projects
Project 1
Project 2
so basically:
- when clicking from Index page to a category, only that category should expand
- when clicking the other category, the current category changes, so the previous category collapses and the other one expands.
and a bonus: is it possible, that when on a single post, there expands another level of info? for example, a few custom fields per post. like this:
graphic design
Other Projects
Project 1
custom field 1
custom field 2
…
Project 2
thank you very much
Try this code
<?php $article_categories = get_categories(array(
'child_of' => get_category_by_slug('graphic design')->term_id
));
$talentChildren = get_categories(array('child_of' => get_category_by_slug('Project 1')->term_id));
?>
<div id="content" class="narrowcolumn" role="main">
<?php if (have_posts()) : ?>
<div class="post-list">
<?php foreach($talentChildren as $talent): ?>
<?php
$talentSubChildren = new WP_Query();
$talentSubChildren->query(array('category_name' => $talent->slug));
?>
<h2><?php echo $talent->name; ?></h2>
<ul>
<?php while ($talentSubChildren->have_posts()) : $talentSubChildren->the_post(); ?>
<li>
<?php talent_thumbnail(); ?>
<h4>
<?php the_title(); ?>
</h4>
<p><?php the_excerpt(); ?></p>
read on »
</li>
<?php endwhile; ?>
</ul>
<?php endforeach; ?>
<?php if($wp_query->max_num_pages!=1):?>
<div class="pagination">
<?php previous_posts_link('« prev') ?>
<span class="current"><?php echo $wp_query->query['paged']; ?></span>
of <span class="total"><?php echo $wp_query->max_num_pages; ?></span>
<?php next_posts_link('next »') ?>
</div><!-- .pagination -->
<?php endif; ?>
</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 get_search_form(); ?>
<?php endif; ?>
</div>
Ive gotten a bit further, but i need some help now.
<?php
// get all the categories from the database
$cats = get_categories();
// loop through the categries
foreach ($cats as $cat) {
// setup the cateogory ID
$cat_id= $cat->term_id;
// Make a header for the cateogry
echo '<h2><a href="./?cat='.$cat->term_id.'">'.$cat->name.'</h2>';
// create a custom wordpress query
query_posts("cat=$cat_id"); ?>
<?php if (in_category($cat_id)) { ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php // create our link now that the post is setup ?>
<?php the_title(); ?><br>
<?php endwhile; ?> <?php endif; // done our wordpress loop. Will start again for each category ?>
<?php } else { ?>
<?php } ?>
<?php } // done the foreach statement ?>
So this is working now: it lists the posts per category, if in the current category, else it doesnt show anything.
now what i still want: i want to add something extra within the loop IF i'm on a single page. I have this code:
<?php wp_reset_query(); ?>
<?php if (is_single('84')) { ?>
Yes
<?php } else { ?>
no
<?php } ?>
But that would mean i have to break a query in the middle of a loop. and the is_single thing does not work inside a loop / without the query reset.
I want it looking like this with above code:
Graphic Design
project 1 (for example id=84)
Yes
project 2 (for example id=101)
No
thanks
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;
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 :)