If you ever tried to use an if statement because you wanted to remove an action on a specific page, you would have noticed that it doesn’t work! Why? Because you can’t just start writing if statements in your functions.php file. It has to be tied to an action.
Here’s a simple way to do this with the Genesis Framework.
In my case, I needed one of my post type pages to look a certain way. I could have used is_single but then ALL of my single pages would have been effected!
Here’s what I tried at first:
Everything seemed OK, but it didn’t work??
Well, it was then that I realized in order to use an if statement like this, it has to be in a function. Your functions.php file won’t read this little bit code.
So what action am I supposed to add it to?
The key here is to remember that we’re editing the loop. The post_meta and post_info are all within the loop of the page.
So if we want to manipulate it, we have to add our action to anything that comes before the loop.
Well, being that Genesis is so freaking awesome and has TONS of hooks you can use, I decided to use the one that makes the most sense.
And voilà! Now the remove_action function will only work on the single post type pages!!
Genesis 2.0 Version NEW
Are you using Genesis 2.0? If so, then this is the code you would use.
About the AuthorWhat's UP! This is my site, I write 99% of the articles on here. I'm also the owner of SureFireWebServices.com. I help out a lot of developers and designers getting into the web game. Helping is fun for me, so feel free to ask me any questions! I've made courses and have a membership as well to help get you on your feet!
You Might also like
By Jonathan Perez — 3 years ago
Many to many posts is a common problem that I keep running into with Types and so do a lot of others. The main question most people ask is “How the hell do you successfully run many to many posts with the Types and Views plugin?” Well to be honest, I’ve been developing for quite some time and it’s still a huge freakin’ pain to do, but I finally found a great way that will make life SO much easier for you in the future.
Why is many to many post relationships such a problem.
Well, for starters, by default Types only allows many to many relationships by hacking it. It’s not directly built into the software (not sure why as it’s been requested for years now). In their documents, they tell you that in order to make many to many relationship type posts, you need to add a third CPT (custom post type).
This is ridiculous because:
- It doesn’t really work in every situation.
- It’s incredibly sloppy.
- Who wants to manage a third post type?!
In order to manage these relationships, you have to create tertiary posts that link the 2 posts together. However, if you have “many to many” which is what’s needed, then you have to create a new post for every single relationship. Cumbersome? Yes
Doesn’t Types have Parent / Child Relations? Can’t you use that?
Here’s how parent / child relationships work in Types.
You have a house (Parent). That house has bedrooms(Child).
You can list as many bedrooms as you want in that house.
NOW, What if you have 2 houses that both have a living room. Not uncommon I’d say. Well, since each child post can only have 1 parent, you have to recreate that living room on the parent post. You can’t reuse child posts that were already created.
If you’re situation is more complex then that, then that’s going to leave you with A LOT of child posts. Now add that tertiary post in, and you can see how this can start getting very very messy.
Now I’m pretty new with this plugin but I did some digging and it truly is the definition of many to many relationships. I think the problem most people have is that it involves a little bit of code. Don’t be scared though, it’s really easy.
If we go back to the house/room example, you can make the living room once, and then just link it to every house if you need without having to constantly recreate the same post over and over. The same works vice versa, create a room, and link it to as many houses as you want.
Here’s the magic that puts it all together, and you can also find this on the P2P documentation page.
First you have to set up the actual posts that need to be related:
[gist id=”4987734d263072362ad9″ file=”p2p_setup.php”]
Then you need to display it
[gist id=”4987734d263072362ad9″ file=”display_p2p.php”]
In the above example I used WooCommerce, so this specific loop hooks into the product summary, but you can literally hook it anywhere you’re theme allows.
That’s it! Now you have access to all the posts in a clean simple format, and they’ll display however you choose.
In my next post, I’ll show you how to actually set up the Views plugin to display the related posts.Post Views: 482
By Jonathan Perez — 1 year ago
NOTE: GUEST POST 🙂 ENJOY
WordPress is a platform that is extensively used for creating blog websites. But have you ever thought of creating a website based on varied themes like fashion, beauty, lifestyle or any other subject of your choice? I guess you would have. Such a website that publishes content on a specific subject or a topic is termed as an online magazine. Having an online magazine that is fancy along with being sophisticated and contains appealing content will attract traffic to it. So, in this blog, I would be making you aware of the steps or techniques that you must implement in order to create a magazine-style website.
Below mentioned points will act as a perfect guide for you when you are looking to create your own online magazine with WordPress.
Having an Intriguing HomePage
It becomes utmost important to have a homepage that highlights the most popular and the recent stories along with displaying other articles. You must display multiple links and extracts from a selection of articles that you have published on your website. Your visitors must be presented with a few short stories and articles to choose from. Using a feature-rich magazine theme will enable you to build a homepage that has plenty of options which will attract visitors to your website. These themes have predefined homepages that are of different genre. This makes it very easy to choose a homepage for your magazine website and you could even find a homepage that fits in your website’s scenario. This will save a lot of your time which could have been invested a developing a homepage.
Top-Notch User Experience
Your online magazine will only become a success if it is able to generate traffic on it. It is important to keep your visitors as long as possible on your website. You will have to give your visitors such a visual appearance that will prompt them to visit your website again and again. This will enable you to create a long lasting impression on the minds of them. Most of the news websites and magazines display adverts which allow them to get monetized. Thus, the more page impressions that are generated by your visitors, you will be able to earn more money from your advertisers. This will only be possible will users choose your website over the others which searching for a particular content or topic.
Selecting a Magazine Theme
When you are looking to create a magazine website, you will come across quite a few of the magazine themes that are offered by WordPress for free. Some of the popular free WordPress magazine themes include Newspaper, Newsmag, TwentyFouteen and many more. You can even choose some of the premium WordPress themes that will offer you more functionalities and features but they will cost you money. The benefits of choosing an appropriate theme for your magazine website is that it will come preloaded based on some genre like lifestyle, heath and fitness, fashion etc. So, if your magazine content falls in the predefined category this will prove very beneficial for you. This will enable you to easily choose any of the themes based on your magazine requirements.
Creating Content for your Magazine Website
In order to create a successful magazine or news website, you will have to publish content that offers value to your target audience. The content you publish will totally depend on the focus of your website. A growth in the number of articles will have a direct impact on your visitors who will be directed to your website as a result of search engine results. Publishing relevant and informative articles will turn out positive for you. Choosing a content format that is appreciated by your audience will be a good ploy. A high-quality content will enable you to gets leads and also rank higher than the websites that are also showcasing a similar content as yours. Grabbing the attention of users is only possible if you rank higher in the search results of popular search engines like Google, Yahoo and Bing. Google also ranks a quality content much higher than the other contents of the same genre.
Growing Your Target Audience
Once you have got initial visitors on your website you will feel the need to grow your audience. The best approach of doing this is to pay for advertising on the social media platforms like Facebook, Twitter or seek assistance from advertising networks and platforms that are related to your topic. One thing which you must surely do is to set up profiles on the popular social media networks. There are some social media platforms that generate huge traffic on certain topics or subjects. Each and every social media platform has an audience of its own. You should also look for sponsorship opportunities, building partnerships with other people or even apply to guest post on related websites to get a link back to your website. Another important component in building your audience is to adopt a strategy while setting up your email newsletter. Persuading your visitors to sign up for your newsletter is a proven methodology to convert one-time visitors into loyal customers.
I hope that the above-mentioned points throw enough light on the parameter that you need to take care of if you want to create a successful online magazine. It would be great to have your views on this post of mine. Do let me know about them in the comments section below.
Sarah Clarke is working as a professionally qualified WordPress Developer at WordSuccor Ltd., a renowned firm providing WordPress Theme Customization Service at very reasonable cost with a global reach. She loves to share her thoughts on WordPress and always looking for learning something new about it. You can follow her company on various social media sites such as Google+, Facebook, and Twitter.Post Views: 1,142
By Jonathan Perez — 6 years ago
So I was working on a project and I added a featured image to the post. There was also an image in the post directly (in the single page view — single.php). So low and behold when I went to the homepage I saw the featured image display perfectly how I wanted and then BAM! the same image right next to it. WHY??? Well I didn’t have anything that told wordpress to display the featured image on the home/archive/category page ONLY and not the images in the post!!!
Until now… Read MorePost Views: 1,964