How to get hyperlink in wordpress php? - php

I am building a website and i have this issue :
I am working on a template and i did some modification. So the front page have some boxes which shows deals and buttons.
As you can see there are buttons called "See Deals"
Each box is a post so when i create a post then each box created automatically . I want that when i put a link on post then it will automatically set behind that "See Deals" button. I mean i want that this "See deal" button take the url from a link which i put in this post.
I wrote this code for boxes :
<div class="price_row_grid">
<div class="price_for_grid floatleft">
<?php theme_create_btn('no', 'price'); ?>
</div>
<div class="floatright vendor_for_grid">
<?php if ($price_meta == 'admin'): ?>
<?php $author_id = $post->post_author; ?>
<a class="admin" href="<?php echo get_author_posts_url($author_id) ?>" title="<?php the_author_meta('display_name', $author_id); ?>">
<?php echo get_avatar($author_id, '22'); ?>
</a>
<?php elseif ($price_meta == 'store'): ?>
<div class="brand_logo_small">
<?php WPSM_Postfilters::re_show_brand_tax('logo'); //show brand logo?>
</div>
<?php endif; ?>
</div>
</div>
<div class="price_row_grid">
<div class="price_for_grid floatleft">
<p class="button">Get Deal</p>
</div>
Now suppose i created a post on wordpress :
Now you can see there i put a dummy link at the end of post "google" now i want that when i put any link there then the box of this post get this link and set behind "Get Deal" button.

Related

WordPress How to link a button to a specific template page?

I have a website with several pages with links/buttons that should lead to a specific page.
Is there a way to link this buttons in a dynamic way, that does not include page ID?
Currently I am doing it this way, with ACF field in which I write in a page ID
<div class="projects-homepage-item">
<?php $projects_page = get_post(get_field('page_id')); ?>
<a href="<?php the_permalink($projects_page->ID); ?>" class="projects-homepage-item-img" target="_blank">
<?php the_post_thumbnail(); ?>
</a>
</div>
Is there something similar to this function that leads to blog/post page?
<div class="news-homepage-btn-wrapper">
<?php printf(__('Pogledaj sve novosti', 'femix')); ?>
</div>

How use Dynamic hyperlink on each wordpress post?

I built a static button from backend but i want that button get hyperlink from post editor
I have designed a static design and button on singlepost.php file now i want that when i create a new post then i want to put a redirect hyperlink behind that button from post editor section. how can i do that ?
how i set hyperlink behind that "Get Deal" button from post page ?
Get Deal button is static for all post but this button take link when i put from post editor section (so there will be separate dynamic link for each post)
My static design code for post is :
<div class="price_row_grid">
<div class="price_for_grid floatleft">
<?php theme_create_btn('no', 'price'); ?>
</div>
<div class="floatright vendor_for_grid">
<?php if ($price_meta == 'admin'): ?>
<?php $author_id = $post->post_author; ?>
<a class="admin" href="<?php echo get_author_posts_url($author_id) ?>" title="<?php the_author_meta('display_name', $author_id); ?>">
<?php echo get_avatar($author_id, '22'); ?>
</a>
<?php elseif ($price_meta == 'store'): ?>
<div class="brand_logo_small">
<?php WPSM_Postfilters::re_show_brand_tax('logo'); //show brand logo?>
</div>
<?php endif; ?>
</div>
</div>
<div class="price_row_grid">
<div class="price_for_grid floatleft">
<p class="button">Get Deal</p>
</div>
Now how i set hyperlink behind "Get Deal" from post editor because i just build button which is static for all pages but i want to set different hyperlink for each page.
you can take a help from this example
<html>
<head>
<script type="text/javascript">
function onsubmit_handler(){
var myForm = document.getElementById('myForm');
var data = document.getElementById('data').value;
if(data == "a")
myForm.setAttribute('action', 'a.php');
else if(data == "b")
myForm.setAttribute('action', 'b.php');
else
myForm.setAttribute('action', 'error.php');
}
</script>
</head>
<body>
<h3>Enter Text:</h3>
<form id="myForm" method="post" onsubmit="onsubmit_handler()">
<input type="text" id="data" name="data" value="">
<input type="submit" value="Post">
</form>
</body>
</html>

Hide a tab with no content on a Magento EE product page

I have successfully added a tab to my view.phtml page located at app/design/frontend/enterprise/aps/template/catalog/product.
I tried an if statement to hide it if the Specifications field is empty, i.e. no content. The issue is, it doesn't work. It still shows the tab even if there is no content.
My code is below at the end of post.
2 Questions:
Am I taking the correct approach? Basically, I am making a tab to have an Expert Review tab. I originally was going to use a cms block, but figured purposing the Specifications field was easier, for one, but also I could ignore the tab if no content
Can you please help ? :)
Thanks so much and here is my code and I attached a screenshot of the empty tabs.
<div class="wa-product-details-tab product-description">
<div class="wa-product-details-tab-heading product-desc-tab">
<div rel=".wa-product-tab-details-item-1" class="wa-product-heading-item wa-product-heading-item-1 wa-product-heading-item-active">
<span>Description</span>
</div>
<div rel=".wa-product-tab-details-item-2" class="wa-product-heading-item wa-product-heading-item-2">
<span>Specs</span>
</div>
<div rel=".wa-product-tab-details-item-3" id="review-form" class="wa-product-heading-item wa-product-heading-item-3">
<?php
$summaryData = Mage::getModel('review/review_summary')
->setStoreId(Mage::app()->getStore()->getId())
->load($_product->getId());
?>
<span >Reviews (<?php echo $summaryData->getReviewsCount();?>)</span>
</div>
<div rel=".wa-product-tab-details-item-4" class="wa-product-heading-item wa-product-heading-item-4">
<span>APS Advisor Review</span>
</div>
</div>
<div class="wa-product-tab-details product-desc">
<div style="display: block;" class="wa-product-tab-details-item wa-product-tab-details-item-1">
<?php echo $_product->getDescription(); ?>
</div>
<div style="display: none;" class="wa-product-tab-details-item wa-product-tab-details-item-2">
<p> <?php echo $this->getChildHtml('additional')?></p>
</div>
<div style="display: none;" class="wa-product-tab-details-item wa-product-tab-details-item-3">
<p>
<?php echo $this->getChildHtml('review_form') ?>
<?php echo $this->getChildHtml('product_additional_data_review') ?>
</p>
</div>
<div style="display: none;" class="wa-product-tab-details-item wa-product-tab-details-item-4">
<?php if ($_product->getSpecifications()); ?>
</div>
</div>
I am not sure if I understood your issue correctly. I am assuming that you want to hide the "APS Advisor Review" tab if there is no content in it.
For this you can use an if condition to check if $_product->getSpecifications() has any content, and show the tab title only if there is any content like this
<?php if( !empty($_product->getSpecifications()) ){ ?> <!-- displays the tab title only if the product has any specifications -->
<div rel=".wa-product-tab-details-item-4" class="wa-product-heading-item wa-product-heading-item-4">
<span>APS Advisor Review</span>
</div>
<php } ?>

Displaying last 3 blog posts on wordpress custom theme

I have a custom theme I am working on in wordpress, and I want to display the last 3 blog posts made onto my home page. I also want to style certain information regarding each post differently, like have the month and year be a certain font, and the day be much bolder and different font as well, along with displaying like a sentence or less of the article, followed by a "..." and "read more" type of thing.
How do I pull data from the blog? I know there are certain wordpress functions that can get me this data but I haven't been able to quite figure out how to do it, I'm not really well versed in the wordpress php functions. Right now I just have it hard coded but it's annoying to have to retype everything when I make a new post. I know you can set to show however many blog posts on the settings->reading but I want to be able to fully customize how it looks.
Let me know any suggestions on how I should go about doing this!
<div class="bottom">
<div class="wrap-2">
<h2>Blog</h2>
<div class="content-div">
<div class="bottom_box">
<div class="btm-img"><h4>April <span>25</span><br />2014</h4></div>
<div class="right_block">
<p class="highlight2">blog title 1</p>
<p class="highlight3">lksj sldkf jsl lsdkfj sdklf sd</p>
Read More >
</div>
</div>
<div class="bottom_box">
<div class="btm-img"><h4>April <span>24</span><br />2014</h4></div>
<div class="right_block">
<p class="highlight2">blog title 2</p>
<p class="highlight3">lsdkjf lsdk fjsl dkkddk lsdkfjpaskldfj;</p>
Read More >
</div>
</div>
<div class="bottom_box">
<div class="btm-img"><h4>April <span>23</span><br />2014</h4></div>
<div class="right_block">
<p class="highlight2">blog title 3</p>
<p class="highlight3">lksdjf slkdfjsldkfj;as dfklsd;j fsld;kfj</p>
Read More >
</div>
</div>
</div>
</div>
</div>
Try the snippet below. Use your custom HTML block (the one with botom_box class) instead of this used below.
<?php $posts = get_posts("numberposts=3"); ?>
<?php if($posts) : ?>
<?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
<!-- your HTML block goes here --->
<div class="post">
<h3><a href="<?php echo get_permalink($post->ID); ?>" ><?php echo $post->post_title; ?></a></h3>
<?php the_excerpt(); ?>" rel="bookmark">read more</a>
</div>
<!-- end of the HTML block -->
<?php endforeach; ?>
<?php endif; ?>

How to make a specific loop for this function that gets the posts?

I am doing some WordPress theming. I have a #novelsslider div. Inside of #novels, I used this code to get the latest three posts in the "novels" category, inside of the html divs, I used some php functions to get the latest 3 posts and load the html 3 times floated to the left to build a slider:
<!-- slider -->
<div id="novelsslider" class="slider">
<? $novels = get_option('of_novels') ?>
<?php query_posts('category_name=$novels&posts_per_page=3'); ?>
<?php while (have_posts()) : the_post(); ?>
<div class="sliderunit">
<?php the_post_thumbnail(); ?>
<div class="novelsslidertitle">
<div class="arrow-left"></div>
<a href="<?php the_permalink(); ?>">
<img class="cross" src="<?php bloginfo('stylesheet_directory'); ?>/images/cross.png"/>
</a>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</div>
</div>
<?php endwhile;?>
<div id="novelsslidebars">
<input type="submit" value="" class="slidebars" id="novelsslidebtnleft">
<input type="submit" value="" class="slidebars" id="novelsslidebtnmiddle">
<input type="submit" value="" class="slidebars" id="novelsslidebtnright">
</div>
</div>
<!-- End novelsslider -->
ow I have some arrows.. I want them when clicked to get a set of previous 3 posts and load them, how can I do such a loop?
To achieve this you can adopt any of these methods :
1- If your posts are not in large number then you can preload them and store in some container which is hidden by default and will appear when you click the next / previous button, like a content slider, but this is a bad approach and not recommended.
2- Use AJAX to load the rest of the posts, this is a good method and will be purely dynamic. Look on the following links to have the idea:
http://wp.tutsplus.com/tutorials/getting-loopy-ajax-powered-loops-with-jquery-and-wordpress/
Wordpress - how can I fetch more posts via AJAX?

Categories