SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru Todd Temple's Avatar
    Join Date
    Mar 2005
    Location
    Tennessee
    Posts
    790
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Rearrange PHP Code

    I have this snippet of code below:
    PHP Code:
    <h1 class="page-title"><?php printf__'Category Archives: %s''twentyten' ), '<span>' single_cat_title''false ) . '</span>' ); ?></h1>
    that returns something like this; "Category Archives: Recent News".

    I am wanting to rearrange the output to read something like this; "Recent News Category Archives".
    Can someone show me how to do this?
    Todd Temple > T2 Design

  2. #2
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,200
    Mentioned
    105 Post(s)
    Tagged
    1 Thread(s)
    Shouldn't it be something as simple as this?

    PHP Code:
    <h1 class="page-title"><?php printf__'%s Category Archives''twentyten' ), '<span>' single_cat_title''false ) . '</span>' ); ?></h1>
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style

  3. #3
    SitePoint Guru Todd Temple's Avatar
    Join Date
    Mar 2005
    Location
    Tennessee
    Posts
    790
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks DaveMaxwell. That worked. I am a PHP noob so it may have been simple for you but I had no idea what I was doing. Thanks again!
    Todd Temple > T2 Design

  4. #4
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,200
    Mentioned
    105 Post(s)
    Tagged
    1 Thread(s)
    No worries. To explain for future use - the %s is what is replaced in the statement, so I just moved it from one place in the statement to the other so you got the format you wanted.
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style

  5. #5
    SitePoint Guru Todd Temple's Avatar
    Join Date
    Mar 2005
    Location
    Tennessee
    Posts
    790
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So the percent symbol is the variable that represents the name of the category, correct?
    Todd Temple > T2 Design

  6. #6
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,813
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Todd Temple View Post
    So the percent symbol is the variable that represents the name of the category, correct?
    Kind of, the %s is a placeholder for a variable; in this case '<span>' . single_cat_title( '', false ) . '</span>' gets placed where the %s is located.

    With printf, you can set placeholders that are replaced when outputted in the order that you list them. Example:
    PHP Code:
    printf('My test with two placeholders %s and %s''this shows up after placeholders''this shows up after and'); 
    There are a lot more placeholders than just %s that can be used with printf, but you won't run into those often in WordPress.
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •