How to display page excerpt in Wordpress - wordpress

I am new in using Wordpress, I created a page that contains a long list of items.
* Item 1
* Item 2
* Item 3
* Item 4 ... and so on
I am planning to embed this page with long list of items on a separate page. How am I going to do it?
I followed tutorials online and got the idea of putting this piece of code add_post_type_support( 'page', 'excerpt' ); on functions.php. After putting the code, an new option will be available when you create/edit pages. But after that, how can I display the my page excerpt?

First to put this code on your theme function.php file.
add_action( 'init', 'my_add_excerpts_to_pages' );
function my_add_excerpts_to_pages() {
add_post_type_support( 'page', 'excerpt' );
}
After that enable excerpt for page see below define image:
Using this code to get page excerpt:
<?php echo get_the_excerpt(); ?>
<?php
query_posts("page_id=36");
while ( have_posts() ) : the_post()
?>
<h1><?php echo get_the_title(); ?></h1>
<?php the_excerpt(); ?>
<?php
endwhile;
wp_reset_query();
?>

Related

ACF fields on WooCommerce Product not displaying

I am customizing an old theme called AmazeTheme which was not specifically made with WooCommerce support. And an woocommerce.php was at theme's root. However with help of plugins like Simply Show Hooks and Show current template I am able to see where to put which info.
But I am having an weird problem. The ACF fields I have added are not visible at all. I even tried to assign the field group inside product loop section.
I also tried the following method.
add_action( 'woocommerce_after_single_product_summary', 'view_acf_field_for_single_product', 10 );
function view_acf_field_for_single_product(){
if (function_exists('the_field')){
the_field('shop_support');
}
}
And inside the loop of single-product.php
<?php while ( have_posts() ) : the_post(); ?>
<?php wc_get_template_part( 'content', 'single-product' );
$dump = get_fields();
?>
<?php endwhile; // end of the loop. ?>
And then did var_dump($dump) at desired place of the file.
This site's php version is 5.6.40 and WooCommerce version is 3.4.8
WP version is 4.9.18
I have looked up many solutions. Also tried the WooCommerce Hooks but still no clue why ACF not showing.
Can you try this code:
add_action( 'woocommerce_after_single_product_summary', 'view_acf_field_for_single_product', 10 );
function view_acf_field_for_single_product(){
global $post;
if (function_exists('the_field')){
the_field('shop_support', $post->ID);
}
}
Not tested.
For some weird reasons, this approach worked for me (path/to/theme/woocommerce/single-product.php):
<?php if (get_field_objects()):
foreach ( get_field_objects() as $field_id => $field ) :
$value = trim($field['value']);
if (!empty($value)) :
?>
<div class="product_field" id="field-<?php echo $field_id; ?>">
<?php the_field($field_id); ?>
</div>
<?php endif; ?>
<?php endforeach; // end of the loop. ?>
<?php endif; ?>
Also the following one for Category (path/to/theme/woocommerce/archive-product.php) pages:
<?php
$extra_info = get_field_object( 'category_details', get_queried_object() );
if ( !empty($extra_info) ) :
?>
<div class="category_field" id="field-<?php echo $extra_info['key']; ?>">
<?php echo $extra_info['value']; ?>
</div>
<?php endif; ?>
Even at these locations, get_fields() did not work.

wordpress theme page not showing plugin gallery

I am new to Wordpress. I am trying to build a theme from scratch.
I created the page.php which is the following:
<?php
/**
* The template for displaying pages
*
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages and that
* other "pages" on your WordPress site will use a different template.
*
* #package nameofpackage
*/
get_header(); ?>
<?php get_footer(); ?>
I also installed the NextGen plugin.
I created a new page, and use the "add Gallery" button of NextGen; i ended up with
[ngg src="galleries" ids="1" display="basic_thumbnail"]
inside the text section of the page (the visual section shows the plugin logo in a box).
When i tried to preview the result i only get the header and the footer with nothing in the middle; the inspector shows no presence of the code related to the gallery.
If i try the same thing with ThemeFifteen it works.
So my question is: is there something i need to include in the function.php that allows my theme to include the output of the plugin in the page? thx
You're missing the WP loop and the_content(), so its absolutely normal to not see anything between the header and the footer. You need something like this for example:
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'loop-templates/content', 'page' );//calling the folder with your loop templates ?>
<?php
// 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;
?>
<?php endwhile; // end of the loop. ?>
And inside your loop template something like :
<article <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<header class="entry-header">
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
</header><!-- .entry-header -->
<?php echo get_the_post_thumbnail( $post->ID, 'large' ); ?>
<div class="entry-content">
<?php the_content(); ?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'understrap' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
<footer class="entry-footer">
<?php edit_post_link( __( 'Edit', 'understrap' ), '<span class="edit-link">', '</span>' ); ?>
</footer><!-- .entry-footer -->
</article><!-- #post-## -->
This is very common way to structure your theme, but please spend some time on beginners tutorials about developing custom themes. It's very easy to get the basic concepts, you'll need couple of hours to get the idea ! This is just an example I want to stress on that, quick and dirty fix of your code would be:
<?php
/**
* The template for displaying pages
*
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages and that
* other "pages" on your WordPress site will use a different template.
*
* #package nameofpackage
*/
get_header(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile; // end of the loop. ?>
<?php get_footer(); ?>
What you're looking for is do_shortcode() See the docs
Make sure to echo it as well.
<?php
get_header();
echo do_shortcode('[ngg src="galleries" ids="1" display="basic_thumbnail"]');
get_footer();
You could also use apply_filters() and pass in the 'the_content' hook. That would render your shortcode with the same hooks/filters as used br the wysiwyg editor in the back-end but ultimately it's just using do_shortcode() behind the scenes.
<?php
get_header();
echo apply_filters('the_content', '[ngg src="galleries" ids="1" display="basic_thumbnail"]');
get_footer();

Show featured image and excerpt of specific page on home page wordpress

I want to display featured image and excerpt of ie. ABOUT page on my home page. Is it possible to do this with pages not posts only?
found the answer in the meantime for the excerpt, now I need only featured image
add new function to functions.php:
//Display page excerpts
add_action( 'init', 'my_add_excerpts_to_pages' );
function my_add_excerpts_to_pages() {
add_post_type_support( 'page', 'excerpt' );
}
and call the function in front-page.php>
<?php echo get_the_excerpt(); ?>
<?php
query_posts("page_id=2");
while ( have_posts() ) : the_post()
?>
<h1>Why US?</h1>
<?php the_excerpt(); ?>
<?php
endwhile;
wp_reset_query();
?>
For the featured image, you need :
1 - to modify your function, to add also thumbnail support
add_action( 'init', 'my_extend-page_functions' );
function my_extend-page_functions() {
add_post_type_support( 'page', array('excerpt', 'thumbnail' );
}
(Have a look on the codex page of all you can add http://codex.wordpress.org/Function_Reference/add_post_type_support )
2- on the front-page, you can use the_post_thumbnail()
http://codex.wordpress.org/Function_Reference/the_post_thumbnail

showing the ten post thumbnail

I want to show latest ten post of my security category with date and post title and the post thumbnail.
To show the pic I have faced with problem. According to this article
http://www.wpbeginner.com/beginners-guide/how-to-add-featured-image-or-post-thumbnails-in-wordpress/
when we want to showing the thumbnail first of all we should have to copy the following code to the function.php file
add_theme_support( 'post-thumbnails' );
and using the
<?php the_post_thumbnail(); ?>
To show pic of the post, I use this code into the loop but it doesn’t work. my code is here:
<?php query_posts('securitysoft=CATEGORYNAME&showposts=10');
while ( have_posts() ) : the_post(); ?>
<br/>
<?php
php the_post_thumbnail();
?>
<br/>
<?php the_time(__('j/F/ Y','kubrick')) ?>
<br/>
<?php the_title();?>
<?php endwhile; ?>
The main problem is that the picture does not show. To prove this I am taking post Id of the post that has thumbnail(292) like this :
<?php if ( has_post_thumbnail(292))
{
echo "<script type='text/javascript'>alert('yes')</script>";
has_post_thumbnail(292);
}
else
{
echo "<script type='text/javascript'>alert('no')</script>";
has_post_thumbnail(292);
}
?>
note:292 is the post id
The result of above code is no.
I have replaced php the_post_thumbnail(); with each one of following code but does not work:
get_the_post_thumbnail($post->ID);
echo get_the_post_thumbnail($post->ID);
get_the_post_thumbnail($post_id, 'thumbnail');
echo get_the_post_thumbnail($post_id, 'thumbnail');
<?php echo get_the_post_thumbnail($post_id, 'thumbnail', array('class' => 'alignleft')); ?>
And this is my function.php :
<?php
add_theme_support( 'post-thumbnails' );
if ( function_exists('register_sidebar') )
register_sidebar();
?>
do you set the feature image!! remember if you don't set the feature image. the image won't display. because this command that you have used only take the thumbnail. to set the feature image go to the feature image panel and click on the Set featured image link.

How can I display only the thumbnail and title of a post in WordPress?

How can I display only the thumbnail and title of a post in WordPress like here: http://themes.premiumpixels.com/?theme=artiste
P.S. I'm not advertising anything, I just posted a question because I have no idea how to do something like that.
// From your loop just remove the_content() or the_excerpt() call
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<!-- do stuff ... -->
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail();
}
post_title();// to display the post title
<?php endwhile; ?>
<?php endif; ?>
You need to do this for the image:
http://www.wpbeginner.com/wp-themes/how-to-add-post-thumbnails-in-wordpress/
And you need to do this for the little text:
Add this in function.php:
add_post_type_support( 'page', 'excerpt' );
then add this below your post_thumbnail in your template as the link demonstrate you:
<?php the_exceprt(); ?>

Resources