is there a way to split the title into 2 text? and split only from the first Hyphen(-)
Sample:
Input: Artist name - Song name
Output:
i found this but its not exactly what i need
Split a WordPress title into two lines
You can simply try this :
$array = explode('-', 'wordpress-title', 2);
Then echo $array[0]; // output wordpress
echo $array[1]; // output title
Related
i want to trim a single word i.e, Monday in wordpress, how can i trim this word?
$my_title = get_the_title();
echo wp_trim_words($my_title, 1, null );
the title coming from database Monday So i want to trim Monday to Mo or M.
wp_trim_words() will works easily without any problems. You can use it with below sample code:
echo wp_trim_words( get_the_title(), 1, '' );
But do note that it will trim the first character in whole post/page title, not regconize the date in your example.
I don't know that wp_trim_words() works that way. I'd recommend just using regex and preg_match():
$my_title = get_the_title();
to get the first character:
$regex = '/(.?)/';
or to get the first two characters, change the variable to this:
$regex = '/(.?)./';
Then get the matches for the regex pattern:
preg_match($regex, $my_title, $matches);
Echo out the first one:
echo $matches[0];
I have several John Jones with different names in a form. I submit the form to another program which uses "$checkednames = implode(', ', $_POST['raters']);". I echo $checkednames and see all the names but "count($checkednames)" is 1 and not the number of names. What could be wrong?
I appreciate any help.
You may seen the results by going to:
www.golfcourseratingassistant.org/ratecourse/
select Course name > Select Tee Box > Course Data ...select for all lists then "Save Data".
Selected data is only valid for the current session.
It will be 1 only, implode() returns a string containing a string representation of all the array elements in the same order, with the glue string between each element. See Manual
explode() will return an array of strings
So count() after explode() will give you the number of elements.
You can see the names because it is one string.
$array = array('lastname', 'email', 'phone');
$comma_separated = implode(",", $array);
echo count($comma_separated);// Output will be 1
For explode():
$string= "lastname,email,phone";
$array= explode(",", $string);
echo count($array); //output will be 3
I am trying to learn how to create my own module and I am stuck. I created text.module, text.install and text.info . It's just a basic module for inputing text.
So now I have the next scenario I input the text in textbox, it saves to a table in the database i can display it into a table like in this:
http://img33.imageshack.us/img33/5815/textyi.jpg
now my question is can you and how can you use function view so that in the picture "ttt" becomes a link so that you can see the title and text "ttt" ?
EDIT :
I figure out something i just need this :
in table I have 3 columns (test_id, title, text)
Now i use
$result = db_query("select title,text from {text} ");
now how can I turn title into a link . Let say that in row 1 col1 of title it stands house. How can i turn house into a link. Do i need to do sometning like this
$result= db_query ("select n.title, n.text form {text} n where n.title = :title", array (":title" => ???? ))
I think this is what you are looking for
<?php
l(t('Link text'), 'about-us', array('attributes' => array('class' => 'about-link')));
?>
http://api.drupal.org/api/drupal/includes%21common.inc/function/l/7 might help u..
I set a session variable upon login, I want to find all rows in a table that have the username in the "Createdby" field and I want to list them on a page. I'm using this code:
<?php
$result = mysql_query("SELECT email FROM members WHERE createdby = '" . $_SESSION['myusername'] ."'");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
while($row = mysql_fetch_row($result))
{
echo ($row[0]);
}
?>
It works great but it doesn't space them, it echoes out like: data1data2 and not separate like data1, data2. How can I customize the results without messing it up? I tried to add
echo ("<p>".$row[0]."</p>");
But received: 11, I'm kind of new to PHP.
This is simply string concatenation. You're adding strings to other strings.
I'd suggest the following just to get started:
echo $row[0].", ";
I also suggest you read up on PHP more, as this is a basic concept in the language.
You can add spaces between each $row[0] like this:
echo $row[0] . ' ';
The dot followed by a space means that you're concatenating a space.
I have 2 level categories like this:
paintings
- car
- cat
- dog
other
- other1
- other2
...
Now I've many posts in each sub-category.
My goal is get the next post and previous post from the current post in current main category.
For example : I've a post name : "a good car" in car category. Then I've a post name : "A big cat " in cat category . Then I've a post name : "a small dog " in dog category.
Now in the "a big cat" post , I'm trying to get the 'a small dog' post as next post and the 'a good car' as prev post.
I'm used :
codex.wordpress.org/Function_Reference/get_next_post
and :
codex.wordpress.org/Function_Reference/get_previous_post
but they still can't get the right post for me.
If I try with :
get_previous_post( false, '' )
I will get the previous post but not in painting category.
Also If I try with:
get_previous_post( true, '' )
I will get only the previous post in the current category , not the painting category.
Anyone can help me ? Thank you!
First, I would be sure that your "cat" paintings belong to both the "cat" and "paintings" categories. By default, I believe, the WordPress PREV/NEXT functions will work the way you're explaining.
i would expect this to work for you, provided your items are included in both the sub and main categories:
<?php previous_post_link('%link', 'Previous in category', TRUE); ?>
More details:
http://codex.wordpress.org/Template_Tags/previous_post_link and
http://codex.wordpress.org/Template_Tags/next_post_link