Okay, so i've got a request for this update which I thought might be simple enough but is turing out a bit tricky than I though.
basically the site has these sub ids for each property 'Vest' and 'Verve' they want each one to be a different colour.
The css that's link to them is <span class="proptery-type-grid"> so obviously I'd add in a second css for each colour, but the id's in the php are being called like this: <span class="proptery-type-grid"<?php echo inspiry_get_property_types( $post->ID );?></span>
so what would be the best way (i'm thinking like a if or else statement) to go about targeting the individual ids to change the colours of them?
Thanks
Maybe you can use a ternary statement? http://us2.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary
Psuedocode:
echo ($post->ID('1') ? '<span class="proptery-type-grid"<?php echo inspiry_get_property_types( $post->ID );?></span>' : '<?php echo inspiry_get_property_types( $post->ID );?>');
I've solved it with
<span class="proptery-type-grid"><?php $post_terms = get_the_terms( $post->ID, 'property-type' );
foreach( $post_terms as $term) {
if( $term->name == 'Verve') {
echo '<span class="proptery-verve">Verve</span>';
} elseif( $term->name == 'Zest') {
echo '<span class="proptery-zest">Zest</span>';
} else {
echo '<span class="proptery-type-grid type-none"></span>';
}
}?></span>
Related
I've got this code below that gets a specific category (from a taxonomy) then displays its sub-categories.
I'm trying to figure out how to add a href link to it, linking to the permalink in order to go to the archive page for that particular sub-category. So far I have this:
<?php
$terms = get_terms( 'job_listing_category', 'parent=59' );
$count = count($terms);
$link_address = the_permalink();
if ( $count > 0 ){
foreach ( $terms as $term ) {
echo "<a href='".$link_address."'><p>" . $term->name . "</p></a>";
}
}
?>
This line: echo "<a href='".$link_address."'><p>" . $term->name . "</p></a>"; seems to be correct, however I need to reference the $link_address somewhere I assume...
I thought I could get the permalink of the sub-category by adding the line: $link_address = the_permalink();
However, this doesn't seem to work and I'm not sure why..
Any help greatly appreciated :)
You can get term link with get_term_link() and you can pass in the term object. You could do:
foreach ( $terms as $term ) {
echo "<a href='" . get_term_link($term) . "'>" . $term->name . "</a>";
}
If you want to save the permalink in a variable, you can use get_the_permalink() instead of the_permalink().
The code below is displaying the title in black text before it displays blue title with hyperlink under it.
I only want the link to appear.
if ( $query2->have_posts() ) {
// The 2nd Loop
while ( $query2->have_posts() ) {
$query2->the_post();
if ($post->ID == $do_not_duplicate)
continue;
$permalink = get_the_permalink($query2->post->ID);
$ID = $post->ID;
$titleAtribute = the_title_attribute();
$title = get_the_title();
echo '<h2 id="post-' .$ID.' ">
<a href="'.$permalink.'" rel="bookmark" title="Permanent Link to '.$permalink.' ">
'.$title.'</a></h2>';
}
// Restore original Post Data
wp_reset_postdata();
}
For example, on my website: http://skkelti.cz/, the following text appears in black above the link with the same text:
-Martin Davídek ml. : „Fanoušci jsou vždy to, co vás žene kupředu“-
Where is this coming from and what do I need to do to stop it from appearing?
The problem is with the_title_attribute(). This is displaying the value directly instead of returning it.
The function accepts echo in $args to specify whether to display or return the value. The default value is true (to display it), so pass false to return the value e.g.:
$titleAtribute = the_title_attribute('echo=0');
I have a custom field in WP that isn't always required and can therefore be left blank. However, the custom field has a word preceding it in the HTML that I'd like to not show if the custom field is left blank.
I think there should be some sort of if/else statement, but am unsure of the exact syntax to get it working.
Code:
<li><span>DATE:</span>
<?php $meta_value = get_post_meta($post->ID, 'date', true);
if (!empty($meta_value)) {
echo '<li>'. $meta_value .'</li>';
} ?>
</li>
Much appreciated
You could put in your if statement what the pre-pended value would be. Let's say it was a $ and a space character.
if (!empty($meta_value) || $meta_value != '$ ') {
You just need to move your if statement out wider a bit:
$meta_value = get_post_meta($post->ID, 'date', true);
if (!empty($meta_value)) {
echo '<li><span>DATE:</span>'
echo '<li>'. $meta_value .'</li>';
echo '</li>';
}
Though, your HTML looks a little astray (you have a list item inside a list item)
This is what I have:
This is what I'm trying to achieve:
This is the code I'm trying to modify to achieve it:
<?php do_action( 'bbp_theme_before_topic_title' ); ?>
<span class="bbp-topic-started-in"><?php
printf( __('<a class="dog" href="%1$s">%2$s</a>', 'bbpress' ),
bbp_get_forum_permalink( bbp_get_topic_forum_id() ),
bbp_get_forum_title( bbp_get_topic_forum_id() ) );
?></span>
<a class="bbp-topic-permalink" href="<?php bbp_topic_permalink(); ?>"><?php bbp_topic_title(); ?></a>
As you can see, it assigns the class "dog" to all forum links. I need it to assign separate classes to the different forums, based on the forum ID, so that I can style them differently.
What I'm thinking is maybe an if statement, but I'm not sure how to execute it properly. Anyone have any suggestions?
You can try something like this:
<?php do_action( 'bbp_theme_before_topic_title' ); ?>
<span class="bbp-topic-started-in">
<?php
$forumId = bbp_get_topic_forum_id();
// Replace these values with your forum IDs and css classes
if ($forumId == 5) {
$class = "dog";
} elseif ($forumId == 6) {
$class = "cat";
} else {
// Remember to specify a default css classname
// in case we didn't match any of the 'if' cases above
$class = "mouse";
}
// Use the $class variable that we set above to dynamically
// replace the classname with the value we want
printf( __('<a class="' . $class. '" href="%1$s">%2$s</a>', 'bbpress' ),
bbp_get_forum_permalink($forumId),
bbp_get_forum_title($forumId);
?>
</span>
Notice how I set bbp_get_topic_forum_id() to a variable and use it both in the if and in the printf further down. Doing this is good practice as it avoids needlessly calling that function multiple times.
I want to list some custom posts (wordpress) and their meta values. Everything works fine so far, but I have to work with empty values too. And I want to use slashes to separate multiple values. So here's what I have so far:
$list = '<div class="clearfix vlist">
<div class="vlist-content">' ;
while($wpex_query->have_posts()) : $wpex_query->the_post();
global $post;
$list .= '<div class="vlist-item">
<div class="title">'.get_the_title().'</div>
<div class="info">'
.get_post_meta( $post->ID, 'wpex_vita_genre', true ).' / '
.get_post_meta( $post->ID, 'wpex_vita_director', true ).' / '
.get_post_meta( $post->ID, 'wpex_vita_role', true ).'</div>
</div>';
endwhile;
wp_reset_query();
return $list . '</div></div>';
Problem comes within div.info, where I want to display 3 values, separated by slashes (/). Soon as one or two values are empty I get stupid double slashes // because these characters are not conditional. I don't know how to make them appear only when there are values to separate because I can't just put an if statement into my $list. I know I know now you people who know php are just shaking heads or doing facepalms because this for sure is easy pie... could you still tell me how to solve this problem?
Thank you!!
I just came across the solution with the right use of conditional statements when defining the meta-values as variables, for example:
if((get_post_meta( $post->ID, 'wpex_vita_genre', true )) != '') $genre = '<span>' . get_post_meta( $post->ID, 'wpex_vita_genre', true ) . ' / </span>';
Simple. Still took me years to get it right. Maybe s.o. will save some seconds reading my solution :D