1

right now, I've started working with Wordpress (and PHP) for the first time in my life. I wonder how CMS works.

All main code should belong to index.php which generates the content. For example, I started making a template from scratch. It has two pages now - home (index) and portfolio. Portfolio is a page that contains image attachments.

I successfully found the way how I can get those images' thumbnails posted into the page, but then I need to pick only one random image and post it into Home (index) page.

Only thing needed is a little change of arguments, but how? I need something like...

if (page == home) then $args = ETC.
if (page == portfolio) then $args = DIFFERENT ETC.

Thank you so much for your support in advance!

Petr Němeček
  • 41
  • 1
  • 3
  • 11

1 Answers1

0

Ideally you're either going to want to create seperate template files or have those differences stored inside of the CMS. Hardcoding information like that in to the templates themselves is not an ideal practice. That being said, the global variable $pagename has the data you're looking for.

How to get the current page name in WordPress?

Community
  • 1
  • 1
zajd
  • 761
  • 1
  • 5
  • 18
  • I don't know if I understood 100% right. My index.php (please, take a look at it): http://pastebin.com/2U6JuqrZ (this code must be applied when /portfolio page is visited, nowhere else) What would you recommend me to do? – Petr Němeček Aug 03 '13 at 21:15
  • You should not be editing index.php - http://codex.wordpress.org/Theme_Development – zajd Aug 03 '13 at 21:19
  • So. I should NOT be editing index.php as long as I don't use posts - but pages - so I DO should use page.php !? Still wondering how to get "Portfolio's" content displayed in "Home" to avoid duplicates of that image (uploading it once again to "Home"). – Petr Němeček Aug 03 '13 at 21:33
  • No, you don't edit any .php files outside of your theme's directory, you can download some existing WordPress templates to get a better idea of how they work. The long and the short of it is that you'll probably have a home.php template and a singlepage.php template. Although it's possible to do it all in one, I don't believe that's the best idea most times. – zajd Aug 03 '13 at 21:45