Closed

Fix and refactor function to accurately input content

I have written a function that inputs content (title, timestamp, comment count, widgets, sections etc) into pages depending on the page.

My code is redundant, but I don't understand PHP well enough to make it not as repetitive. I also am running into a few errors where incorrect info is being added to the page. I believe I am passing an incorrect ID or I should be passing the ID in a different way or maybe this is because I am outside the loop? I am not sure...

The end goal is to have this function reduced in size (cleaned up with not as many if statements and not as many attempts to get the ID) and for it to accurately check and input the content I am asking it to input (home page, archive page, category page, taxonomy page, single page, regular page, search page, 404 page etc... you get the idea)

I'll walk you through my function for you to understand what is happening - but it's pretty straightforward. Functions are placed in my pages and these functions are only called if the page has checked the section to show. See screenshots for more info.

Please note that the one function shown in the image is just ONE of the functions... The first image shows all the separate sections and they each have their own function with their own checks.

Ok. So I have been asked to rewrite this.... here goes..

This is the Wordpress starter theme that I have built: https://base.crazystupidsmart.com/

I have written functions that input content into pages (title, timestamp, comment count, a map section etc). The only way that this content is shown on the page though is if the page has a checkmark telling the function to show or not.

View the used-options.png image attached to view a screenshot of these options. These options can be seen in the upper right hand corner of the screenshot and are available on each Wordpress page and post across this entire theme. So basically every page and every post gives the ability to hide or show certain content/info.

View the map-function.png image attached to view a screenshot of the map section function. This will show the logic being performed when a user decide whether or not they want their page or post to show a map section.

You can see that I basically input code into the page depending on if the page has this option checked or not. The checks I am processing to accomplish this are simple. Look at the code screenshot again and then I'll explain two example:

1st Check Example
// inputs map always if page is a 404 or search page (doesn't check outside options - simply executes if the one statement is true)
<?php if (is_search() OR is_404()) { css_inner_map_section(); } ?>

2nd Check Example
// inputs map only if the page is an archive or index page AND the page option is set to show (checks what kind of template is being used and then checks the outside options and only executes if BOTH statement are true)
<?php elseif (is_archive() OR is_home()) { if ($map_check_global == 'no') { css_inner_map_section(); } else {} } ?>

So again... the first section would input the map to those two pages regardless of any check, and the second section checks to see if the page is an archive page or index page and then checks to see if that page is supposed to be hiding the section or not. These are the types of checks that are being processed to show all the info on the pages.

By leaving the last "else" empty I can ensure that all the content that is supposed to be "hidden" never even loads onto the page. So this is my way of limiting HTTP requests on pages - and I can effectively hide/show sections of code without using CSS or jQuery. :)

Ok... Now look at this page: https://base.crazystupidsmart.com/articles/

Now view the unused-options.png image attached to view a screenshot of the blog page options being left empty so that all the content is input into the page.

Starting to make sense what I am doing?

This blog page you should be looking at (index.php) is an example where all the content is showed.. you can see the title, description, author, timestamp, total comment count, testimonial section, contact section, map section and footer section... and the only reason you can see all that is because I have not checked any of my boxes to hide them. :) So I think this is very cool and helpful for customization.

So what is the problem?

The problem is that sometimes I am getting the wrong info on certain pages or the info I am trying to hide is actually showing up (this happens only on a few odd pages like a taxonomy page, or the home page). All this is happening as a result of the "checks" that I am performing. I am unfamiliar with the Wordpress page hierarchy and am certain the issue is being caused because:

1) I am not performing my PHP IF statements in the correct order
2) I am possibly passing in the wrong ID

Also, my code is quite redundant, but I don't understand PHP well enough to make it not as repetitive.

The end goal is to have this function reduced in size (cleaned up - with not as many if statements and not as many attempts to get the ID) and for it to accurately check and input the content I am asking it to input (home page, archive pages, category pages, taxonomy pages, single pages, regular pages, search page, 404 page etc... you get the idea).

Any Questions? Again - most all of this is already working and working quite well. I just know there has to be more proficient ways to do this.

Skills: HTML5, PHP, WordPress

See more: fix my home page, fix my home, content writing for travel websites from home, you will be translating document content accurately into natural, bad content different without www fix, magento home page display product details single, change home page category magento, home improvement category, fix number images virtuemart category view, content spinning function, loader as2 fix size, fix size picture, fix size frontpage joomla, actionscript fix size swf, joomla fix size post frontpage, fix size picture size picture, gridlayout swing fix size, fix size photos, fix size web page, archive page specific category wordpress, problem design masterpage aspnet fix size, fix size pictures, fix size swf loaded flash, input proper utf indicate encoding fix, fix size swf

About the Employer:
( 30 reviews ) Greenville, United States

Project ID: #12230628

10 freelancers are bidding on average $38 for this job

infoway

Thanks for inviting us, We would like to check the code if you provide us the credentials. can you come over a CHAT to have a discussion regarding the issue in detail? Regards, AG Technical Consultant Infoway L More

$33 USD in 1 day
(399 Reviews)
9.4
arhamsoftltd

Hello Tad, Good Day! I am a full stack PHP developer with 10 years experience, I am very much comfortable to fix the issue and refactor function to accurately input content. I want to work on hourly basis for thi More

$30 USD in 2 days
(111 Reviews)
8.2
chapter19vw

SATISFACTION GUARANTEED This is Neha from SDLC Labs (IT Outsourcing Company India). SDLC is having specialization in WordPress|PHP and have developed lots of sites (1000+sites) in the past to connect clients and More

$105 USD in 1 day
(81 Reviews)
7.4
vtechiti

Dear Employer, Thanks for inviting me : I have gone through your requirement and will be glad to work for you. Please take a look of some of the website done by me: =========================================== More

$38 USD in 1 day
(333 Reviews)
7.3
VnBestSolutions

Dear Sir. We claim to get it done perfectly for you EXACTLY in the way you want it - Kindly give we a chance and we will prove myself - Ready to prove our words, let's get it done right away and I mean RIGHT AWAY !! Lo More

$45 USD in 1 day
(162 Reviews)
6.7
amutinda

A proposal has not yet been provided

$35 USD in 1 day
(36 Reviews)
4.8
chrisjackson3

How are you? Dear sir. I read the job description with interest. I now know your issue of job exactly. I will complete this job by correcting bootostrap and css perfectly. I can complete this for 1d. I ha More

$25 USD in 1 day
(9 Reviews)
2.9
bccrashedul

Hello, Thanks for the opportunity. I have gone through the details of your project and we find it well within our capabilities. I would like to tell you that I have a very strong experience of more than 3+ years More

$15 USD in 1 day
(3 Reviews)
2.1
mikcs

hello dear i have a great skills in asp.net, php framewroks and wp cms and its customization and wp plugin customization, designing of sites using bootstrap js etc followings are few urls which i hade made and run s More

$25 USD in 1 day
(2 Reviews)
1.3
$20 USD in 3 days
(1 Review)
0.7
ogiters

We are professional web designer and development company. We have done critical work in php , we would like to do your job .

$27 USD in 2 days
(0 Reviews)
0.0
zackgrogan

A proposal has not yet been provided

$20 USD in 1 day
(0 Reviews)
0.0