I am running WordPress functions on an external webpage to get posts and pages. The functions work fine.
I am using
the_content();
to display the body of the posts but it doesn't seem to be keeping the correct formatting. The HTML is displaying fine, but the line breaks etc are not.
Here is the full PHP code i am using:
$page = get_page_by_id($_GET["p"], OBJECT, 'post');
query_posts('p='.$page->ID.'');
if($page->ID) {
while (have_posts()) {
the_post(); ?>
<h2><?php the_title(); ?></h2><br>
Posted on <?php the_date(); ?><br><br>
<?php
the_content();
}
}
Screenshot of my site: http://postimg.org/image/nc2xw6af3/
Screenshot of the Wordpress Template: http://postimg.org/image/r01znya1p/
Looks like the required CSS information is missing. You need to include the CSS for <h2> and <p> tags from the WordPress template.
Related
I've created my own WordPress custom theme for a website that I'm working on. It's my first time building a theme from scratch! I'm having a difficulty 1st: to link several pages to the fron-page, or home page. For example lets say that I want to link "Who we are", page + "Contact us", page, etc.. How can I make WordPress understands that each page is different, and link to it? here is what I did so far:
in page.php I placed this code:
<?php get_header(); ?>
<div class="container">
<?php
if (have_post()) {
while(have_post()) {
the_post();
get_template_part( 'template-parts/content', 'page');
}}
?>
</div>
<?php get_footer(); ?>
I also created a content-page.php where I've placed my HTML code. (I'm building the whole thing with an HTML and CSS code that's just like building a website from scratch).
I also want to know when using a plugin, how can I connect that into the pages that I'm adding. For example, if I'm installing a form such as WpForms for a page like "Contact us" how can I link that?
Please let me know if my questions need more details
If I understand this correctly...
You want to be able to display (link) a couple of pages to your home page?
Ex:
[home page content here]
[Connect page content here] [Blurb page here]
If so, you need to pull in the page content into the home page.
Something like:
<?php
$postid = 0 /*Need to get page id, that's the key */;
//Pull in the page data
$featured_page = get_post($postid);
$thumbnail = get_the_post_thumbnail( $featured_page->ID );
//Only show the excerpt in this case
$content = apply_filters( 'the_content', $featured_page->post_excerpt );
?>
<article id="post-<?php echo $featured_page->ID ?>">
<header class="entry-header">
<h1><?php echo $featured_page->post_title ?></h1>
</header>
<div class="entry-content">
<div class="thumbnail">
<?php echo $thumbnail; ?>
</div>
<div>
<?php echo $content; ?>
</div>
</div>
Important! You'll need to get the page id from somewhere. You can hard-code it in, but that's risky if something changes. You can set up an Customizer option that lets the user select what page to use.
https://codex.wordpress.org/Theme_Customization_API
As for the contact form etc. I'd suggest putting it on a page as a shortcode, then displaying the full page, not the excerpt.
I use this code for a theme I built myself. If you need anymore help, let me know, I can show you where to find it.
I'm trying to use shortcode in post to display gallery but on website it puts out shortcode itself as text.I'm using
<?php the_content();?>
in php file.
Same shortcode works well with
<?php echo do_shortcode('[shortcode here]')?>
but in this case I need it to be shortcode in post editor.
No need to write PHP code and just put [shortcode here] in the WordPress Post Editor.
If you want to use short code in wordpress post editor then no need to write php code.
And if you want to user the_content() in any wordpress .php file then you need to write and follow code pattern.
for example (example of single.php)-
<?php
while (have_posts()) : the_post();
the_title();
the_content();
endwhile;
?>
Lets consider that you are on the checkout page, in the dashboard > Pages > Checkout Page you enter this [woocommerce_checkout] and
In page-checkout.php file of your wordpress you can write your custom code to make it work.
Here is an example of my custom code :
<?php
if (have_posts()) : while (have_posts()) :
the_post(); ?>
<div class="container">
<div class="checkout-page my-4">
<?php the_content(); ?>
</div>
</div>
<?php endwhile; endif; ?>
Sorry for bad English :-P
Try adding following code in your active themes functions.php
add_filter( 'the_content', 'do_shortcode' );
On my frontpage i have a news module that basicly just shows the 5 newest posts from a news category. this is hardcoded into the design likeso:
<h2>Nyheder</h2>
<?php query_posts('category_name=nyheder&posts_per_page=5'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post();?>
<?php the_time('M j, Y'); ?> - <?php the_title(); ?><br /><br />
<?php endwhile; endif; ?>
for some reason when i press one of the news links in this section on my frontpage it displays the news post on my frontpages design but it removes the code that displays the other news topics on the sidebar.
the entire site and problem can be wieved here http://www.acagenturs.dk - Below the jquery banner there is 2 sections. 1 with some text and the other with the title Nyheder. Try pressing one of the news items.
edit: i am displaying the content of the post like this:
<?php wp_reset_query(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>
Edit: I have now discovered that when pressing one of the news post links taking me to a post page it also ruins my javascripts controlling the menu. this is very odd
Wordpress have two types of post pages, one shows only part of the post and no comments, and the other shows everything. I don't know hoe your site is structured, but make sure that you are using that function on both pages.
For what I see, there's no logic in your code making stuff disapear...
I have created the file latest.php in the public_html so that when I go to www.domain.com/latest.php it will show me the latest articles. Sadly, nothing of the posts came up. Later, I will sort them with other ways (mostly based on custom fields).
This is my latest.php file (I removed any styling for better understanding)
<?php include("wp-load.php"); ?>
<?php get_header(); ?>
<?php wp_head(); ?>
**AND HERE IS WHAT I COPY-PASTED FROM MY INDEX.PHP THAT IS WORKING**
<?php while (have_posts()) : the_post(); ?>
<a title="" href="<?php echo get_permalink(); ?>" ><?php the_title(); ?></a>
<?php endwhile; // End the loop ?>
<?php posts_nav_link(' ยท ', 'previous page', 'next page'); ?>
My question is how can I make it possible to show the latest articles with pagination ? wp-load.php , wp_head and get_header are loaded correctly.
Should I use an entire different method for my task? If yes, which one?
wordpress does not works this way... if you want to make a custom page. create a new template page in the themes folder and then (from back end) create a new page and assign that template to that page.. this way you can put you custom code in the template file and wordpress can process it
I have installed wordpress on my site located at www.example.com/blog. on www.example.com I'd like to retrieve the top 5 latest blog posts and display date, url and blog title. Is this possible?
This means I want to get the blog posts from outside the wordpress installation using php and do a loop.
<?php
$loop = new WP_Query('showposts=5&orderby=ID&order=DESC');
if($loop->have_posts()): while($loop->have_posts()): $loop->the_post();
?>
<div class="post" id="post-<?php the_ID(); ?>">
<?php the_title(); ?>
<span class="post-meta">
<?php the_time('F jS, Y'); ?> by <?php the_author_posts_link(); ?>
</span>
</div>
<?php endwhile; else: ?>
No recent posts yet!
<?php endif; ?>
See: WordPress Loop, query_posts(), WP_Query(). There are also plugins to get recent posts.
Yes you can use the RSS feed of your blog. Its a standard wordpress feature. Use a javascript (or some server side) rss client to fetch the top 5 entries from RSS feed and show it on your homepage.One such script is http://p3k.org/rss/
Use WP_Query like sugested by Sepehr and after you include wp-blog-header.php add this:
header("HTTP/1.1 200 OK");
This overrides WP's security check.
Yes you can.
in wordpress you must use blog in blog plugin. if it's use you set tempalte form your design and put the shortcode like "[blog_in_blog category_slug='my-category-slug' num=5]" in your cms page or php file and you display first 5 post with date any where in your site. you must create categories and put in short code.
blog in blog :- http://wordpress.org/plugins/blog-in-blog/