• First off, I have searched extensively for a resolution or suggestions regarding this topic. I may not have titled the topic correctly.

    I am using this install of WordPress as a CMS and not a blogging tool. I chose to use WordPress because I did not want to deal with the bloated code that comes along with Joomla and Drupal. I also really do not need anything most of what is included in the core of those two platforms. As many already know, WordPress is much easier to template.

    Here is what I am trying to accomplish:

    I need these pages to dynamically generate a logo. There are 120 logos. Here is what I am thinking.

    Create a function that searches the page title, and if that title is found generate logo x.

    In addition, I have created 12 functions that will display depending on what page template is chosen for each page (located in user-functions.php which is called on in the themes functions.php file). I am wondering if there is a plugin, or a simple block of code that will allow me to edit the contents of this function in the admin area of wordpress

    I am somewhat new to WordPress, and still trying to fully understand the loop and how to plugin to the loop to accomplish what I need. Any advice on how to accomplish this would be greatly appreciated.

Viewing 5 replies - 16 through 20 (of 20 total)
  • Thread Starter taylor11

    (@taylor11)

    Got everything working smoothly with this code, I probably should not have used another ereg_replace to remove the leftover “amp” from “&” but it is working as expected.

    <?php
    $imgtype = '.png'; // Image type, be sure to remember the period
    $directory = 'wp-content/test/'; // Where your files are located
    $ptitle = the_title('','',false); // The title, return=false so not to echo/return value
    $logo = ereg_replace('[^A-Za-z0-9]', '', $ptitle ); // Remove all special characters
    $logo = ereg_replace('amp', '', $logo ); // Remove the remaining "amp" from "&amp;"
    
    $logoresult = get_bloginfo('siteurl').'/'.$directory.$logo.$imgtype; // Build a complete path for image src
    $logodefault = get_bloginfo('siteurl').'/'.$directory.'default'.$imgtype; // Default image
    $logocheck = $directory.$logo.$imgtype; // Pure relative path for file_exists function
    $file = file_exists($logocheck);
    ?>
    <?php if($file) : // If the file exists ... ?>
      <img src="<?php print $logoresult; ?>" alt="<?php print $ptitle; ?>" />
    <?php else : // If the file does not exist, use default ... ?>
      <img src="<?php print $logodefault; ?>" alt="<?php print $ptitle; ?>" />
    <?php endif; ?>

    Any thoughts on my other issue of the same page name but different logos need to be displayed? Your opinion may help get the ball rolling – would like to avoid using different page templates for these pages.

    Well how are you going to differentiate from each page if they have the same name?

    Is there anything uniquely different about each page? Other then ID of course.

    Thread Starter taylor11

    (@taylor11)

    Other than page ID, nothing.

    I can search for a tag and add something that differentiates the pages, if something exist.

    Can we use the page slug?

    Associate them with a custom field perhaps…

    I’m not sure i fully understand the reasoning in having multiples with the same name.

    Thread Starter taylor11

    (@taylor11)

    I don’t either, but the person I am doing the project for seems to have this issue in his naming structure.

Viewing 5 replies - 16 through 20 (of 20 total)
  • The topic ‘Function to search page title and generate a logo’ is closed to new replies.