Here is the hierarchy of the theme:
Hierarchy1:
Hierarchy1
Hierarchy2:
Hierarchy 2
And here is the post content used from single.php:
Post,single.php
and here is an example mock up how i want to be seen the posts in the news category:Example post content
Thank you.
There are too many templates in your theme directory. Are you sure you are doing things correctly?
Lets start afresh. Tell from the beginning what you are trying to accomplish and what you have achived so far. What has worked or you and what has not. Where are you facing the issues. Please be as detailed as possible.
And here is the post content used from single.php:
Post,single.php
Is that a post or a page. What is the url?
and here is an example mock up how i want to be seen the posts in the news category:Example post content
Again, what is the url?
Also what is the url of the archives?
Also it would be a very good idea to install this plugin
It shows which template is being used by WordPress to show the current page or post or archive.
Open different links (posts, pages, archives) -especially the ones for which you have attached the screenshot in your previous reply- and see which template they are using and list it here.
Then check whether the template being used is actually the one you are expecting to
Lastly it would be very helpful if you could post the url to your site.
If it is on localhost, then it is a different matter
I have this plug in, the url is post, i know i have to many templates,and i could be more optimal if i used archive-{myslug}.php but i started it like this, and now i find difficult to change it.(When i fulfill the site i will try to change it. )Both urls are posts,displaying from single.php the second i havent made it yet, but it is also a post with different css.
Okay. Now if I understand correctly, the second one too being a single post, will be using single.php. Its just that you want it to be displayed differently than other single posts. Correct?
Well, this could be easy. But for that please post the code of single.php here
here is the code of single.php:
<?php
/**
* The template for displaying all single posts
*
* @link https://developer.ww.wp.xz.cn/themes/basics/template-hierarchy/#single-post
*
* @package South_Arch
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
while ( have_posts() ) : the_post();
get_template_part( 'template-parts/content', get_post_format() );
endwhile; // End of the loop.
?>
</main><!-- #main -->
</div><!-- #primary -->
<?php
get_footer();
and here is for content.php:
<?php
/**
* Template part for displaying posts
*
* @link https://codex.ww.wp.xz.cn/Template_Hierarchy
*
* @package South_Arch
*/
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="PostContent">
<header class="entry-header">
<?php
if ( is_single() ) :
the_title( '<div class="entry-title">', '</div>' );
else :
the_title( '<div class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></div>' );
endif;
if ( 'post' === get_post_type() ) : ?>
<div class="entry-meta">
</div><!-- .entry-meta -->
<?php
endif; ?>
</header><!-- .entry-header -->
</div>
<div class="entry-content">
<?php
the_content( sprintf(
/* translators: %s: Name of current post. */
wp_kses( __( 'Continue reading %s <span class="meta-nav">→</span>', 'south-arch' ), array( 'span' => array( 'class' => array() ) ) ),
the_title( '<span class="screen-reader-text">"', '"</span>', false )
) );
wp_link_pages( array(
'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'south-arch' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
</article><!-- #post-## -->
One way would be to edit single.php and change the line
get_template_part( 'template-parts/content', get_post_format() );
to something like this:
if(is_single() && has_category('news')):
get_template_part( 'template-parts/content-news', get_post_format() );
else:
get_template_part( 'template-parts/content', get_post_format() );
endif;
Then you create the file content-news.php and write the code to display the post in news category on whatever way you want
-
This reply was modified 9 years, 1 month ago by
Shariq Khan.
-
This reply was modified 9 years, 1 month ago by
Shariq Khan. Reason: Adding the closing bracket for the if condition
-
This reply was modified 9 years, 1 month ago by
Shariq Khan.
It is also the same with post types?because I search it,a little complicated, declare the post types, assign them and then use them with single-{post-type }.php
That is another question.
First let us know whether the above solution worked for your problem
Yeah it works! Thank you very much.
Good.
Hope you have better understanding of templating system now.
If your problem is still not solved and you have further questions related to this, please post them here.
If they are not related, please post them as a separate topic.