my search result doesn't show excerpt content of pages on WordPress it only show for the post
advise please
Taken from http://codex.wordpress.org/Function_Reference/add_post_type_support
<?php
add_action('init', 'my_custom_init');
function my_custom_init() {
add_post_type_support( 'page', 'excerpt' );
}
?>
Adds excerpt support for the 'Page' post type. Paste this code into your themes functions.php file (ref http://codex.wordpress.org/Functions_File_Explained)
Related
I have two codes. The first one I am using on page.php and it displays content from any pages I create in the admin panel. The second code works to display my posts on the mainpage just not sure where that code should go.
It works if I place it in the page.php but then the same content (posts) are shown on any pages I create. I tried placing the second code in home.php and index.php at the same time as using the first code in page.php but does not work.
if (have_posts()): while (have_posts()): the_post();
wp_title(''); echo '<br />';
the_content(); echo '<br />';
endwhile; endif;
<--- Second Code -->
$args = array( 'posts_per_page' => 10 );
$lastposts = get_posts( $args );
foreach ( $lastposts as $post ) :
setup_postdata( $post ); ?>
<div id="pbox">
<div id="pthumb"><?php the_post_thumbnail( array(100,100) ); ?></div>
<div id="pcontent">
<?php the_title(); ?>
<?php the_excerpt(); ?><br />
Post Category: <?php the_category( ', ' ); ?>
</div>
</div>
<?php endforeach;
wp_reset_postdata(); ?>
I think you should take a look at the following: https://developer.wordpress.org/themes/basics/template-hierarchy/#home-page-display
You'll notice that, if present, home.php is the file that WP will use to display your posts page - if of course a page separate to your normal front page has been set in Settings > Reading > Posts page.
Then in home.php, you can add whatever you like, ie -
<?php
$args = array(
'show_option_all' => '',
'orderby' => 'name'
);
wp_list_categories( $args );
?>
To clarify, if home.php doesn't exist in your theme, WP will then look for index.php.
There are same query post for page.php,single.php because it will just fetch content. you can differentiate by as follows.
Home Page display add same code (query post) in fallowing
1) home.php
2)index.php
front-page.php – Used for both “your latest posts” or “a static page”
as set in the front page displays section of Settings → Reading.
home.php – If WordPress cannot find front-page.php and “your latest
posts” is set in the front page displays section, it will look for
home.php. Additionally, WordPress will look for this file when the
posts page is set in the front page displays section.
page.php – When “front page” is set in the front page displays
section. index.php – When “your latest posts” is set in the front
page displays section but home.php does not exist or when front page
is set but page.php does not exist.
Single Post
The single post template file is used to render a single post. WordPress uses the following path:
single-{post-type}-{slug}.php – (Since 4.4) First, WordPress looks
for a template for the specific post. For example, if post type is
product and the post slug is dmc-12, WordPress would look for
single-product-dmc-12.php.
single-{post-type}.php – If the post type is product, WordPress would
look for single-product.php.
single.php – WordPress then falls back to single.php.
singular.php – Then it falls back to singular.php.
index.php – Finally, as mentioned above, WordPress ultimately falls
back to index.php.
Single Page
The template file used to render a static page (page post-type). Note that unlike other post-types, page is special to WordPress and uses the following patch:
custom template file – The page template assigned to the page. See
get_page_templates().
page-{slug}.php – If the page slug is recent-news, WordPress will
look to use page-recent-news.php.
page-{id}.php – If the page ID is 6, WordPress will look to use
page-6.php. page.php
singular.php
index.php
Detailed Explanation: click here
I am making a wordpress theme
But the problem is i can not enable feature image option in Portfolio
I have added the following code in the function.php
add_theme_support( "post-thumbnails", array('portfolio', 'post'));
This code is working for posts but not for portfolio
is it because of any of these plugins that i am using
Advanced Custom Fields
Custom Post Type UI
Akismet
enter image description here
try this in fucntion.php file
function custom_theme_setup() {
add_theme_support( 'post-thumbnails', array('post', 'page', 'popup') );
}
add_action( 'after_setup_theme', 'custom_theme_setup');
I'm a bit stumped on this one. I'd like to create a page that is an archive of all posts of a certain category - and show excerpts. However, Reading through the Wordpress docs, they say a page cannot be a post or associated with categories.
So, I'm now wondering if this is possible or if there is a work around. I'd really like to put this on a page as I'd like to have a custom sidebar as well. Is this possible with a custom page template? Any other ways this can be done that I am not thinking of?
Thanks!
You can add this function to functions.php and then you can call it from any page template.
If you need to create a new page template for the sidebar.
FTP, download page.php
rename page.php to page-custom.php (custom can be anything, just make sure its page-whatever.php
In the page-custom.php
Replace the comments section with (Custom Template Name can be anything you want)
/**
* Template Name: Custom Template Name
*
*/
replace the loop in your new template with a call to get_posts_custom('catSlug');
then add this to your functions.php
if(!function_exists('get_posts_custom')){
function get_posts_custom($catSlug){
$args=array(
'post_type' => 'post',
'post_status' => 'publish',
'category_name' => $catSlug,
'ignore_sticky_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<article class="post">
<time class="date"><?php the_time('m.d.y') ?></time>
<p><strong><?php the_title(); ?></strong>
<?php the_excerpt(); ?>
</p>
</article>
<?php
endwhile;
}
wp_reset_query();
}
}
Reference http://codex.wordpress.org/Class_Reference/WP_Query
I didn't fully test the function, but I am using a modified version of the same code. Mine doesn't filter on the category slug, so that may need tweaking, but I did test to make sure it didnt break functions.php
Create a page, lipsum for example.
Create a PHP file with the page-[the title].php, page-lipsum.php for this example.
Write your loop in that file.
FTP that file to the directory of your theme.
When you go to the URL for that page, the results should be what you're looking for.
I would like to be able to pull all of the pages from my custom theme into one page template, but still allow all of the pages to be displayed according to the selected page template.
In other words, if I have a page template called 'Main' where I pull all of the page data into, and I create a page called 'Home', I would like this page to display on the 'Main' template according to the page template I have selected for the 'Home' page. Is this possible to do?
Thanks,
JW
Alright, so I am going to answer my own question here. I did some research on my own and modified some code from an tutorial to Ajaxify a theme. What needs to happen is this.
In your page.php file, or whatever template you want to use as your main page template, add this.
<?php query_posts( array('post_type'=>'page', 'posts_per_page' => 1000, 'orderby' => 'menu_order', 'order' => 'ASC') ); ?>
<?php if(have_posts()): while(have_posts()): the_post(); ?>
<?php
global $post;
$slug = $post->post_name;
locate_template(
array(
"template-$slug.php",
'template-main.php'
), true
);
?>
<?php endwhile; endif; ?>
Then add your page templates to the theme, and name according to the page slug i.e. template-about.php, or template-home.php. You can then have all of your content displayed dynamically in a one page site and be able to use the default Wordpress pages. I hope I was clear on this, and if not, feel free to let me know, and I'll do my best to clarify.
use in all your page templates this:
include 'page.php';
and then in page.php you can use this:
if (is_page_template('page_temp_one.php')) { ... }
I'm creating a custom post type for creating gallery posts. One of the things I took out was the 'editor' section since I have my own uploader. Since the HTML editor is gone (can't use shortcodes now), is there a wp function which is the equivalent of the [gallery] shortcode?
As per the Codex recommendation for outputting the [gallery] shortcode content directly in a template file, I would use do_shortcode():
<?php do_shortcode( '[gallery]' ); ?>
You can even pass accepted parameters:
<?php do_shortcode( '[gallery columns="4" size="medium"]' ); ?>
Got it. Here's the code for anyone else who wants to do the same thing. Throw this baby in your theme template file and try it out.
$images = get_children(array('post_parent'=>$post->ID, 'post_type'=>'attachment', 'post_mime_type' => 'image'));
foreach($images as $image){
echo wp_get_attachment_link($image->ID);
}
You can use the wordpress function make for this purpose
gallery_shortcode(array('orderby'=>ID));
by sure to call this after you setup the post