In wordpress Twenty Eleven theme how to show read more after one post without writing any <!--read more--> in post page
Go wordpress admin panel and click reading under reading, choose summary instead of full text. That will help you.
Dashboard --> Settings --> Reading and click on "Summary" instead of "Full text"
EDIT:
The above settings for feeds. for showing in the home page, While you adding post put your cursor where you want to add "more" tag and then click Alt+Shift+T or click the button left to spell checker it will insert a more tag on your posts. I think this might work..
use the_excerpt() function in your post and add filter excerpt_more and add readmore.. link.
here this blog uses same function which is develop by me [Latest smartphone apps][1]
[1]: http://latestsmartphoneapps.com here on index page all post summery is given and readmore.. link is given which then display full post.
If you want such functionality let me know.
Use this code for Excerpt.
<?php query_posts('cat=ID'.'&showposts=NO. OF POST') ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h3><?php the_title(); ?></h3>
<?php the_post_thumbnail(); ?>
<p><?php echo substr(get_the_excerpt(), 0,65).' [...]'; ?></p>
Read More...
<?php endwhile; ?>
<?php wp_reset_query(); ?>
<?php endif;?>
The a look at the_excerpt
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 am using my own custom WordPress theme and I am running into trouble displaying the content of blog posts. I can display the title and the date it was published using php but I can't get any of the paragraphs, images, headings, etc. to display on the page. I am using Gutenberg blocks (default) for the content of the blog posts.
I have tried using php functions to grab the content but they don't seem to be working.
<div class="col-md-6 col-md-offset-3">
<p class="date"><span class="glyphicon glyphicon-time">
</span> <?php echo get_the_date();?></p><br />
<p><?php $content = apply_filters('the_content', $post-
>post_content);?></p>
</div>
I am expecting the content of the post to display within the div container but the function is not grabbing the content. Any help would be appreciated!
It sounds like you may be trying to retrieve the post content from outside the loop.
If you look at the post template for a theme e.g. 2017, it is this bit that does the magic. It’s not even necessary to pass a post ID:
<?php
while ( have_posts() ) : the_post();
get_template_part( 'components/page/content', 'page' );
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
endwhile; // End of the loop.
?>
E.g. you should just be able to do:
<?php
while ( have_posts() ) : the_post();
the_content();
endwhile; // End of the loop.
?>
Might be a good idea to start with the code on the link above, or copy the single.php file for the theme you’re using and use that as the basis for your custom post page?
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'm pretty new to WordPress but have spent some 50 odd hours studying up on it, trying things out and such and have the feeling I got a pretty good handle on it now..
However the one thing I simply cannot get working is to have a page spit out a list of posts of a certain category.
Here is my example: http://dev.jannisgundermann.com/zoeikin/graphic-design/typographic-posters
I have a post that if I go to it directly works correctly, but does not show up on this page.
The post direct link.
The category id is '3' while the category name is 'typographic-posters'.
I have a custom page template for the typographic-posters page that looks like this:
<?php
/*
Template Name: Typographic Posters
*/
?>
<?php get_header(); ?>
<?php get_sidebar(); ?>
<?php if (in_category('3')): ?>
<div class="post">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<div class="post-description">
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
</div>
<?=get_image('flutter-image');?>
</div>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
</div>
<?php endif; ?>
<?php get_footer(); ?>
Using this code however the page only shows gets the header, sidebar and nothing else..
If someone could help me out that would really help me get a handle on this filtering of wordpress categories.
Thanks for reading,
Jannis
in_category will only work outside of the loop on a single page. I suggest using the query_posts function to solve this problem. You may use query_posts('cat=3') or query_posts('category_name=typographic-posters') to get the posts you are looking for.
Once obtained, just use the normal WordPress loop to access these posts.
The easiest way is to create a file called category-3.php and use the standard code from normal index.php or category.php file. Wordpress will take care of fetching posts only from category with id=3 and it's child categories.
in_category will only work outside of the loop on a single page. I
suggest using the query_posts function to solve this problem. You may
use query_posts('cat=3') or
query_posts('category_name=typographic-posters') to get the posts you
are looking for.
Once obtained, just use the normal WordPress loop to access these
posts.
This worked excellent, but make sure that you go into Settings > Reading and set the posts page to the -- Select -- option or it will override this query and dump all recent posts there regardless of category.
Simply add before the loop:
<?php query_posts="cat=3&showposts=5">
This will force the loop to display 5 posts (showposts=5) from category 3 (cat=3).
I would 2nd Eimantas' suggestion. The Template Hierarchy will use the category-3.php to display posts in that category. Usually you can just copy a theme's index.php or category.php to category-3.php and adjust that template for any customization you need. Plus the category template will better support pagination of posts.
But if you need to stick with a Page to display those posts, also see the Page of Posts example.
http://codex.wordpress.org/Template_Tags/query_posts
Just so you know where these answers are coming from...there are a lot more interesting functions you can do with query_posts as well.
This plugin could also help you if you want to be able to change the displayed categories without going through the code :
http://wordpress.org/extend/plugins/advanced-category-excluder/
I have filtered post by category Id using the method below:
query_posts('cat=1&showposts=3');
if (have_posts()) : while (have_posts()) :
// if(1) {
//echo the_category_ID();
the_post();
/**
* The default post formatting from the post.php template file will be used.
* If you want to customize the post formatting for your homepage:
*
* - Create a new file: post-homepage.php
* - Copy/Paste the content of post.php to post-homepage.php
* - Edit and customize the post-homepage.php file for your needs.
*
* Learn more about the get_template_part() function: http://codex.wordpress.org/Function_Reference/get_template_part
*/
$is_post_wrap++;
if($is_post_wrap == '1') {
?><div class="post-wrap clearfix"><?php
}
get_template_part('post', 'homepage');
if($is_post_wrap == '3') {
$is_post_wrap = 0;
?></div><?php
}
endwhile;
else :
get_template_part('post', 'noresults');
endif;
thank you for sharing on your thought its a great thought. Usually you can just copy a theme's index.php or category.php to category-3.php and adjust that template for any customization you need