简体   繁体   中英

Wordpress have index.php and single.php show the same content

I have a custom blog page. www.example.com/blog

In index.php I have put all the code to show the blog posts. When a user clicks on one of the blog items it goes to single.php . The code in single.php is an exact copy of index.php .

How can I have index.php or single.php call the other so that I don't need to copy/paste the same code to two files every time I make an edit (if I can even remember to do that).

I think you're not using wordpress correctly.

In your case i would create a shortcode, and place it wherever you want.

Shortcode info here .

Clean up index.php and single.php, and use the WP admin to create pages/posts with that shortcode.

Regards, Bjorn

If you Look in the codex for hierarchy of files...you will see that the Index.php will used for single.php when no Single.php is available.

So if you have exactly the same Code for both, just delete the Single.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM